C# TimeSpan Subtraction

Description

TimeSpan Subtraction subtracts a specified TimeSpan from another specified TimeSpan.

Syntax

TimeSpan.Subtraction has the following syntax.


public static TimeSpan operator -(
  TimeSpan t1,
  TimeSpan t2
)

Parameters

TimeSpan.Subtraction has the following parameters.

  • t1 - The minuend.
  • t2 - The subtrahend.

Returns

TimeSpan.Subtraction method returns An object whose value is the result of the value of t1 minus the value of t2.

Example

The following example calculates difference with the Subtraction operator.


using System;/*from  w  w  w  .j a v  a  2  s  . c o  m*/

class MainClass
{
    static void Main( )
    {
        TimeSpan Left = new TimeSpan( 2, 0, 0 );

        Console.WriteLine( Left - new TimeSpan( 0, 120, 0 ));
    } 
} 

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version