C# DateTimeOffset Add

Description

DateTimeOffset Add adds a specified time interval to a DateTimeOffset object.

Syntax

DateTimeOffset.Add has the following syntax.


public DateTimeOffset Add(
  TimeSpan timeSpan
)

Parameters

DateTimeOffset.Add has the following parameters.

  • timeSpan - A TimeSpan object that represents a positive or a negative time interval.

Returns

DateTimeOffset.Add method returns An object whose value is the sum of the date and time represented by the current DateTimeOffset object and the time interval represented by timeSpan.

Example

The following example uses the DateTimeOffset.Add.


using System;//w  w  w. j  a  v  a  2s .  com

public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset takeOff = new DateTimeOffset(2014, 6, 1, 7, 55, 0, 
                                 new TimeSpan(-5, 0, 0));
    DateTimeOffset currentTime = takeOff;
    currentTime = currentTime.Add(new TimeSpan(2, 25, 0));
    Console.WriteLine(currentTime);
    
  }
}

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