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.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var