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.
備註
你也可以透過呼叫ToString帶有「M」或「MM」自訂格式規格的方法,建立物件月份組件的字串表示DateTimeOffset。