Freigeben über


DateTimeOffset.Month Eigenschaft

Definition

Ruft die Monatskomponente des durch das aktuelle DateTimeOffset Objekt dargestellten Datums ab.

public:
 property int Month { int get(); };
public int Month { get; }
member this.Month : int
Public ReadOnly Property Month As Integer

Eigenschaftswert

Die Monatskomponente des aktuellen DateTimeOffset Objekts, ausgedrückt als ganze Zahl zwischen 1 und 12.

Beispiele

Im folgenden Beispiel wird die Monatskomponente eines DateTimeOffset Werts auf drei verschiedene Arten angezeigt:

  • Durch Abrufen des Werts der Month-Eigenschaft.

  • Durch Aufrufen der ToString(String) Methode mit dem Formatbezeichner "M".

  • Durch Aufrufen der ToString(String) Methode mit dem Formatbezeichner "MM".

DateTimeOffset theTime = new DateTimeOffset(2008, 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 example produces the following output:
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 09.
let theTime = DateTimeOffset(2008, 9, 7, 11, 25, 0, DateTimeOffset.Now.Offset)
printfn $"The month component of {theTime} is {theTime.Month}."

printfn $"""The month component of {theTime} is{theTime.ToString " M"}."""

printfn $"""The month component of {theTime} is {theTime.ToString "MM"}."""

// The example produces the following output:
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
//    The month component of 9/7/2008 11:25:00 AM -08:00 is 09.
Dim theTime As New DateTimeOffset(#9/7/2008 11:25AM#, _
                                       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 example produces the following output:
'    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
'    The month component of 9/7/2008 11:25:00 AM -08:00 is 9.
'    The month component of 9/7/2008 11:25:00 AM -08:00 is 09.

Hinweise

Die Month Eigenschaft ist vom Wert der Offset Eigenschaft nicht betroffen.

Sie können auch eine Zeichenfolgendarstellung der Monatskomponente eines DateTimeOffset Objekts erstellen, indem Sie die ToString Methode mit den benutzerdefinierten Formatbezeichnern "M" oder "MM" aufrufen.

Gilt für: