C# TimeSpan Subtract

Description

TimeSpan Subtract returns a new TimeSpan object whose value is the difference between the specified TimeSpan object and this instance.

Syntax

TimeSpan.Subtract has the following syntax.


public TimeSpan Subtract(
  TimeSpan ts
)

Parameters

TimeSpan.Subtract has the following parameters.

  • ts - The time interval to be subtracted.

Returns

TimeSpan.Subtract method returns A new time interval whose value is the result of the value of this instance minus the value of ts.

Example

The following example creates several pairs of TimeSpan objects and calculates their difference with the Subtract method.


// Example of the TimeSpan.Add( ) and TimeSpan.Subtract( ) methods. 
using System;
/*  w  w w. j  a  v  a  2 s.co  m*/
class TimeSpanAddSubDemo
{
    static void Main( )
    {
         Console.WriteLine(new TimeSpan( 1, 20, 0 ).Subtract(new TimeSpan( 0, 45, 10 )));
    } 
} 

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