C# DateTimeOffset Subtract(TimeSpan)

Description

DateTimeOffset Subtract(TimeSpan) subtracts a specified time interval from the current DateTimeOffset object.

Syntax

DateTimeOffset.Subtract(TimeSpan) has the following syntax.


public DateTimeOffset Subtract(
  TimeSpan value
)

Parameters

DateTimeOffset.Subtract(TimeSpan) has the following parameters.

  • value - The time interval to subtract.

Returns

DateTimeOffset.Subtract(TimeSpan) method returns An object that is equal to the date and time represented by the current DateTimeOffset object, minus the time interval represented by value.

Example

The following example illustrates subtraction that uses the Subtract method.


/*from ww  w  . j  ava 2s.  c  o m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset originalTime, localTime;
    
    originalTime = new DateTimeOffset(2014, 3, 11, 3, 0, 0, 
                                      new TimeSpan(-6, 0, 0));
    localTime = originalTime.ToLocalTime();
    Console.WriteLine("Converted {0} to {1}.", originalTime.ToString(), 
                                               localTime.ToString());   

  }
}
    

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