C# DateTimeOffset AddMonths

Description

DateTimeOffset AddMonths adds a specified number of months to the current DateTimeOffset object.

Syntax

DateTimeOffset.AddMonths has the following syntax.


public DateTimeOffset AddMonths(
  int months
)

Parameters

DateTimeOffset.AddMonths has the following parameters.

  • months - A number of whole months. The number can be negative or positive.

Returns

DateTimeOffset.AddMonths method returns An object whose value is the sum of the date and time represented by the current DateTimeOffset object and the number of months represented by months.

Example

The following example uses the AddMonths method.


using System;/*  ww w  .  j  av  a  2  s  . co m*/

public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset quarterDate = new DateTimeOffset(2014, 1, 1, 0, 0, 0, 
                                     DateTimeOffset.Now.Offset);
    quarterDate = quarterDate.AddMonths(3);
    Console.WriteLine(quarterDate);

  }
}

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