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 该属性。

适用于