C# DateTimeOffset AddYears
Description
DateTimeOffset AddYears
adds a specified number of years
to the DateTimeOffset object.
Syntax
DateTimeOffset.AddYears
has the following syntax.
public DateTimeOffset AddYears(
int years
)
Parameters
DateTimeOffset.AddYears
has the following parameters.
years
- A number of years. The number can be negative or positive.
Returns
DateTimeOffset.AddYears
method returns An object whose value is the sum of the date and time represented by the current
DateTimeOffset object and the number of years represented by years.
Example
The following example displays the latest possible date on which a person must be born in order to legally be issued a driver's license.
using System;/*from w ww .j ava 2 s. c o m*/
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset dateToday = DateTimeOffset.Now;
DateTimeOffset latestBirthday = dateToday.AddYears(-1);
Console.WriteLine(latestBirthday);
}
}
The code above generates the following result.