DateTimeOffset.TimeOfDay 屬性

定義

取得目前 DateTimeOffset 物件之一天中的時間。

public:
 property TimeSpan TimeOfDay { TimeSpan get(); };
public TimeSpan TimeOfDay { get; }
member this.TimeOfDay : TimeSpan
Public ReadOnly Property TimeOfDay As TimeSpan

屬性值

TimeSpan

自午夜起已經過之目前日期的時間間隔。

範例

下列範例會 TimeOfDay 使用 屬性來擷取時間,並將其顯示至主控台。

DateTimeOffset currentDate = new DateTimeOffset(2008, 5, 10, 5, 32, 16,
                                      DateTimeOffset.Now.Offset);
TimeSpan currentTime = currentDate.TimeOfDay;
Console.WriteLine("The current time is {0}.", currentTime.ToString());
// The example produces the following output:
//       The current time is 05:32:16.
let currentDate = DateTimeOffset(2008, 5, 10, 5, 32, 16, DateTimeOffset.Now.Offset)
let currentTime = currentDate.TimeOfDay
printfn $"The current time is {currentTime}."
// The example produces the following output:
//       The current time is 05:32:16.
Dim currentDate As New DateTimeOffset(#5/10/2008 5:32:16AM#, _
                                      DateTimeOffset.Now.Offset) 
Dim currentTime As TimeSpan = currentDate.TimeOfDay
Console.WriteLine("The current time is {0}.", currentTime.ToString())
' The example produces the following output: 
'       The current time is 05:32:16.

備註

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

屬性 TimeOfDay 會以 物件的形式 TimeSpan 傳回 物件的時間元件 DateTimeOffset 。 它相當於 DateTime.TimeOfDay 屬性。

適用於