DateTimeOffset.TimeOfDay DateTimeOffset.TimeOfDay DateTimeOffset.TimeOfDay DateTimeOffset.TimeOfDay Property


取得目前 DateTimeOffset 物件之一天中的時間。Gets the time of day for the current DateTimeOffset object.

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


自午夜起已經過之目前日期的時間間隔。The time interval of the current date that has elapsed since midnight.


下列範例會使用TimeOfDay屬性來解壓縮時間,並將它顯示在主控台中。The following example uses the TimeOfDay property to extract the time and display it to the console.

DateTimeOffset currentDate = new DateTimeOffset(2008, 5, 10, 5, 32, 16, 
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.
Dim currentDate As New DateTimeOffset(#5/10/2008 5:32:16AM#, _
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.


屬性的值Offset不會影響屬性。TimeOfDayThe TimeOfDay property is not affected by the value of the Offset property.

屬性會以物件的形式傳回DateTimeOffset物件的時間元件。 TimeSpan TimeOfDayThe TimeOfDay property returns the time component of a DateTimeOffset object in the form of a TimeSpan object. 它相當於DateTime.TimeOfDay屬性。It is equivalent to the DateTime.TimeOfDay property.