Get the year component of the date represented by the current DateTimeOffset in CSharp
Description
The following code shows how to get the year component of the date represented by the current DateTimeOffset.
Example
using System;/*from w ww . ja va 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.