DateTimeOffset.Day 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得由目前 DateTimeOffset 物件所表示之月份中的第幾天。
public:
property int Day { int get(); };
public int Day { get; }
member this.Day : int
Public ReadOnly Property Day As Integer
屬性值
目前 DateTimeOffset 物件的天數元件,以 1 到 31 之間的數值表示。
範例
下列範例會以三種不同的方式顯示 物件的 day 元件 DateTimeOffset :
藉由擷取 屬性的值 Day 。
使用 「d」 格式規範呼叫 ToString(String) 方法。
使用 「dd」 格式規範呼叫 ToString(String) 方法。
DateTimeOffset theTime = new DateTimeOffset(2007, 5, 1, 16, 35, 0,
DateTimeOffset.Now.Offset);
Console.WriteLine("The day component of {0} is {1}.",
theTime, theTime.Day);
Console.WriteLine("The day component of {0} is{1}.",
theTime, theTime.ToString(" d"));
Console.WriteLine("The day component of {0} is {1}.",
theTime, theTime.ToString("dd"));
// The example produces the following output:
// The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
// The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
// The day component of 5/1/2007 4:35:00 PM -08:00 is 01.
let theTime = DateTimeOffset(2007, 5, 1, 16, 35, 0, DateTimeOffset.Now.Offset)
printfn $"The day component of {theTime} is {theTime.Day}."
printfn $"""The day component of {theTime} is{theTime.ToString " d"}."""
printfn $"The day component of {theTime} is {theTime:dd}."
// The example produces the following output:
// The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
// The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
// The day component of 5/1/2007 4:35:00 PM -08:00 is 01.
Dim theTime As New DateTimeOffset(#5/1/2007 4:35PM#, _
DateTimeOffset.Now.Offset)
Console.WriteLine("The day component of {0} is {1}.", _
theTime, theTime.Day)
Console.WriteLine("The day component of {0} is{1}.", _
theTime, theTime.ToString(" d"))
Console.WriteLine("The day component of {0} is {1}.", _
theTime, theTime.ToString("dd"))
' The example produces the following output:
' The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
' The day component of 5/1/2007 4:35:00 PM -08:00 is 1.
' The day component of 5/1/2007 4:35:00 PM -08:00 is 01.
備註
您也可以使用 「d」 或 「dd」 自訂格式規範呼叫 ToString 方法來建立物件的日元件字串表示 DateTimeOffset 。