DateTimeOffset.Month Właściwość

Definicja

Pobiera składnik miesiąca daty reprezentowanej przez bieżący DateTimeOffset obiekt.

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

Wartość właściwości

Składnik miesiąca bieżącego DateTimeOffset obiektu wyrażony jako liczba całkowita z zakresu od 1 do 12.

Przykłady

Poniższy przykład przedstawia składnik DateTimeOffset miesiąca wartości na trzy różne sposoby:

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.

Uwagi

Właściwość Month nie ma wpływu na wartość Offset właściwości.

Można również utworzyć reprezentację DateTimeOffset ciągu składnika miesiąca obiektu, wywołując ToString metodę z specyfikatorami formatu niestandardowego "M" lub "MM".

Dotyczy