TimeSpan.Subtraction(TimeSpan, TimeSpan) 연산자

정의

지정된 TimeSpan을 지정된 다른 TimeSpan에서 뺍니다.

public:
 static TimeSpan operator -(TimeSpan t1, TimeSpan t2);
public static TimeSpan operator - (TimeSpan t1, TimeSpan t2);
static member ( - ) : TimeSpan * TimeSpan -> TimeSpan
Public Shared Operator - (t1 As TimeSpan, t2 As TimeSpan) As TimeSpan

매개 변수

t1
TimeSpan

피감수입니다.

t2
TimeSpan

감수입니다.

반환

t1 값에서 t2 값을 뺀 결과를 값으로 가지는 개체입니다.

예외

반환 값이 TimeSpan.MinValue 보다 작거나 TimeSpan.MaxValue보다 큽니다.

예제

다음 예제에서는 빼기 연산자를 사용하여 TimeSpan 주간 작업일의 총 길이를 계산합니다. 또한 더하기 연산자를 TimeSpan 사용하여 빼기 작업에 사용하기 전에 일별 중단의 총 시간을 계산하여 총 실제 일일 작업 시간을 계산합니다.

var startWork = new TimeSpan(08,00,00);
var endWork = new TimeSpan(18,30,00);
var lunchBreak = new TimeSpan(1, 0, 0);
var breaks = new TimeSpan(0, 30, 0);

Console.WriteLine("Length of work day: {0}", 
                  endWork - startWork);
Console.WriteLine("Actual time worked: {0}",
                  endWork - startWork - (lunchBreak + breaks));                  

// The example displays the following output:
//     Length of work day: 10:30:00
//     Actual time worked: 09:00:00
let startWork = TimeSpan(08,00,00)
let endWork = TimeSpan(18,30,00)
let lunchBreak = TimeSpan(1, 0, 0)
let breaks = TimeSpan(0, 30, 0)

printfn $"Length of work day: {endWork - startWork}"
printfn $"Actual time worked: {endWork - startWork - (lunchBreak + breaks)}"

// The example displays the following output:
//     Length of work day: 10:30:00
//     Actual time worked: 09:00:00
Module Example
   Public Sub Main()
      Dim startWork As New TimeSpan(08,00,00)
      Dim endWork As New TimeSpan(18,30,00)
      Dim lunchBreak As New TimeSpan(1, 0, 0)
      Dim breaks As New TimeSpan(0, 30, 0)
      
      Console.WriteLine("Length of work day: {0}", 
                        endWork - startWork)
      Console.WriteLine("Actual time worked: {0}",
                        endwork - startwork - (lun\chBreak + breaks))                  
   End Sub
End Module
' The example displays the following output:
'     Length of work day: 10:30:00
'     Actual time worked: 09:00:00

설명

이 연산자에 대 한 해당 메서드는 TimeSpan.Subtract(TimeSpan)

적용 대상