C# DateTimeOffset Addition
Description
DateTimeOffset Addition
adds a specified time interval
to a DateTimeOffset object that has a specified date and time, and yields
a DateTimeOffset object that has new a date and time.
Syntax
DateTimeOffset.Addition
has the following syntax.
public static DateTimeOffset operator +(
DateTimeOffset dateTimeOffset,
TimeSpan timeSpan
)
Parameters
DateTimeOffset.Addition
has the following parameters.
dateTimeOffset
- The object to add the time interval to.timeSpan
- The time interval to add.
Returns
DateTimeOffset.Addition
method returns An object whose value is the sum of the values of dateTimeTz and timeSpan.
Example
The Addition method defines the addition operation for DateTimeOffset values. It enables code such as the following:
/*from w w w . j a va 2s. co m*/
using System;
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset date1 = new DateTimeOffset(2014, 1, 1, 13, 32, 45,
new TimeSpan(-5, 0, 0));
TimeSpan interval1 = new TimeSpan(2, 3, 30, 0);
TimeSpan interval2 = new TimeSpan(5, 0, 0, 0);
DateTimeOffset date2;
Console.WriteLine(date1);
date2 = date1 + interval1;
Console.WriteLine(date2);
date2 += interval2;
Console.WriteLine(date2);
}
}
The code above generates the following result.