DateTimeOffset.Month 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得目前 DateTimeOffset 物件所表示之日期的月份元件。
public:
property int Month { int get(); };
public int Month { get; }
member this.Month : int
Public ReadOnly Property Month As Integer
屬性值
目前 DateTimeOffset 物件的月份元件,以 1 到 12 之間的整數表示。
範例
下列範例會以三種不同的方式顯示值的月份元件 DateTimeOffset :
藉由擷取 屬性的值 Month 。
使用 「M」 格式規範呼叫 ToString(String) 方法。
使用 「MM」 格式規範呼叫 ToString(String) 方法。
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.
備註
您也可以使用 「M」 或 「MM」 自訂格式規範呼叫 方法來建立 ToString 物件的月份元件的字串表示 DateTimeOffset 。