DateTimeOffset::ToLocalTime Method ()


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

Converts the current DateTimeOffset object to a DateTimeOffset object that represents the local time.

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

DateTimeOffset ToLocalTime()

Return Value

Type: System::DateTimeOffset

An object that represents the date and time of the current DateTimeOffset object converted to local time.

In performing the conversion to local time, the method first converts the current DateTimeOffset object's date and time to Coordinated Universal Time (UTC) by subtracting the offset from the time. It then converts the UTC date and time to local time by adding the local time zone offset. In doing this, it takes account of any adjustment rules for the local time zone.

Both the value of the current DateTimeOffset object and the value of the DateTimeOffset object returned by the method call represent the same point in time. That is, if both are passed to the DateTimeOffset::Equals(DateTimeOffset, DateTimeOffset) method, the method will return true.

If the conversion causes a time that is out of range of the DateTimeOffset type, the ToLocalTime method returns a DateTimeOffset object that has the date and time set to either MaxValue or MinValue and the offset set to the local time zone offset.

The following example uses the ToLocalTime method to convert a DateTimeOffset value to local time in the Pacific Standard Time zone. It also illustrates the method's support for the local time zone's adjustment rules.

No code example is currently available or this language may not be supported.

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