DateTimeOffset.Month DateTimeOffset.Month DateTimeOffset.Month DateTimeOffset.Month Property

定義

現在の DateTimeOffset オブジェクトによって表される日付の月要素を取得します。Gets the month component of the date represented by the current DateTimeOffset object.

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

プロパティ値

現在の DateTimeOffset オブジェクトの 1 ~ 12 の整数で表される月要素。The month component of the current DateTimeOffset object, expressed as an integer between 1 and 12.

次の例では、 DateTimeOffset値の月の部分を3つの異なる方法で表示します。The following example displays the month component of a DateTimeOffset value in three different ways:

  • Monthプロパティの値を取得する。By retrieving the value of the Month property.

  • "M" ToString(String)書式指定子を使用してメソッドを呼び出す。By calling the ToString(String) method with the "M" format specifier.

  • "MM" ToString(String)書式指定子を使用してメソッドを呼び出す。By calling the ToString(String) method with the "MM" format specifier.

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.      
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.      

注釈

プロパティは、 Offsetプロパティの値の影響を受けません。 MonthThe Month property is not affected by the value of the Offset property.

また、"M" または "MM DateTimeOffset " カスタム書式指定子を使用ToStringしてメソッドを呼び出すことによって、オブジェクトの month コンポーネントの文字列表現を作成することもできます。You can also create a string representation of a DateTimeOffset object's month component by calling the ToString method with the "M" or "MM" custom format specifiers.

適用対象