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.





















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