TimeSpan.Subtraction(TimeSpan, TimeSpan) Operador

Definición

Resta un TimeSpan especificado de otro TimeSpan especificado.Subtracts a specified TimeSpan from another specified 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

Parámetros

t1
TimeSpan

Minuendo.The minuend.

t2
TimeSpan

Sustraendo.The subtrahend.

Devoluciones

Objeto cuyo valor es el resultado del valor de t1 menos el valor de t2.An object whose value is the result of the value of t1 minus the value of t2.

Excepciones

El valor devuelto es menor que MinValue o mayor que MaxValue.The return value is less than MinValue or greater than MaxValue.

Ejemplos

En el ejemplo siguiente se usa el operador de resta TimeSpan para calcular la longitud total del día laborable semanal.The following example uses the TimeSpan subtraction operator to calculate the total length of the weekly work day. También utiliza el operador de suma TimeSpan para calcular el tiempo total de los saltos diarios antes de usarlo en una operación de sustracción para calcular el tiempo de trabajo diario total real.It also uses the TimeSpan addition operator to compute the total time of the daily breaks before using it in a subtraction operation to compute the total actual daily working time.

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
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

Comentarios

El método equivalente para este operador es TimeSpan.Subtract(TimeSpan)The equivalent method for this operator is TimeSpan.Subtract(TimeSpan)

Se aplica a