共用方式為


DateTimeOffset.Day 屬性

定義

取得由目前 DateTimeOffset 物件所表示之月份中的第幾天。

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

屬性值

Int32

目前 DateTimeOffset 物件的天數元件,以 1 到 31 之間的數值表示。

範例

下列範例會以三種不同的方式顯示 物件的 day 元件 DateTimeOffset

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.

備註

屬性 Day 不會受到 屬性的值 Offset 影響。

您也可以使用 「d」 或 「dd」 自訂格式規範呼叫 ToString 方法來建立物件的日元件字串表示 DateTimeOffset

適用於