C# DateTimeOffset Year
Description
DateTimeOffset Year
gets the year component of the date
represented by the current DateTimeOffset object.
Syntax
DateTimeOffset.Year
has the following syntax.
public int Year { get; }
Example
The following example displays the year component of a DateTimeOffset value in four different ways:
using System;//from www . j ava 2 s . c o m
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset theTime = new DateTimeOffset(2014, 2, 17, 9, 0, 0,
DateTimeOffset.Now.Offset);
Console.WriteLine("The year component of {0} is {1}.",
theTime, theTime.Year);
Console.WriteLine("The year component of {0} is{1}.",
theTime, theTime.ToString(" y"));
Console.WriteLine("The year component of {0} is {1}.",
theTime, theTime.ToString("yy"));
Console.WriteLine("The year component of {0} is {1}.",
theTime, theTime.ToString("yyyy"));
}
}
The code above generates the following result.