C# DateTimeOffset Subtraction(DateTimeOffset, TimeSpan)
Description
DateTimeOffset Subtraction(DateTimeOffset, TimeSpan)
subtracts
a specified time interval from a specified date and time, and yields a new
date and time.
Syntax
DateTimeOffset.Subtraction(DateTimeOffset, TimeSpan)
has the following syntax.
public static DateTimeOffset operator -(
DateTimeOffset dateTimeOffset,
TimeSpan timeSpan
)
Parameters
DateTimeOffset.Subtraction(DateTimeOffset, TimeSpan)
has the following parameters.
dateTimeOffset
- The date and time object to subtract from.timeSpan
- The time interval to subtract.
Returns
DateTimeOffset.Subtraction(DateTimeOffset, TimeSpan)
method returns An object that is equal to the value of dateTimeOffset minus timeSpan.
Example
The Subtraction method defines the subtraction operation for DateTimeOffset objects. It enables code such as the following:
// ww w . ja v a 2 s . com
using System;
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset offsetDate = new DateTimeOffset(2014, 12, 3, 11, 30, 0,
new TimeSpan(-8, 0, 0));
TimeSpan duration = new TimeSpan(7, 18, 0, 0);
Console.WriteLine(offsetDate - duration);
}
}
The code above generates the following result.