Get the month component of the date represented by the current DateTimeOffset in CSharp
Description
The following code shows how to get the month component of the date represented by the current DateTimeOffset.
Example
using System;//w w w. j a va 2 s. co m
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset theTime = new DateTimeOffset(2014, 9, 7, 11, 25, 0,
DateTimeOffset.Now.Offset);
Console.WriteLine("The month component of {0} is {1}.",
theTime, theTime.Month);
Console.WriteLine("The month component of {0} is{1}.",
theTime, theTime.ToString(" M"));
Console.WriteLine("The month component of {0} is {1}.",
theTime, theTime.ToString("MM"));
}
}
The code above generates the following result.