DateTimeOffset.TimeOfDay Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the time of day for the current DateTimeOffset object.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public TimeSpan TimeOfDay { get; }

Property Value

Type: System.TimeSpan

The time interval of the current date that has elapsed since midnight.

The TimeOfDay property is not affected by the value of the Offset property.

The TimeOfDay property returns the time component of a DateTimeOffset object in the form of a TimeSpan object. It is equivalent to the DateTime.TimeOfDay property.

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, 
                                      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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: