DateTime::ToLocalTime Method ()


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

Converts the value of the current DateTime object to local time.

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

DateTime ToLocalTime()

Return Value

Type: System::DateTime

An object whose Kind property is Local, and whose value is the local time equivalent to the value of the current DateTime object, or MaxValue if the converted value is too large to be represented by a DateTime object, or MinValue if the converted value is too small to be represented as a DateTime object.

The local time is equal to the Coordinated Universal Time (UTC) time plus the UTC offset. For more information about the UTC offset, see TimeZone::GetUtcOffset. The conversion also takes into account the daylight saving time rule that applies to the time represented by the current DateTime object.


On Windows XP systems, the ToLocalTime method recognizes only the current adjustment rule when converting from UTC to local time. As a result, conversions for periods before the current adjustment rule came into effect may not accurately reflect the difference between UTC and local time.

Starting with the .NET Framework version 2.0, the value returned by the ToLocalTime method is determined by the Kind property of the current DateTime object. The following table describes the possible results.




This instance of DateTime is converted to local time.


No conversion is performed.


This instance of DateTime is assumed to be a UTC time, and the conversion is performed as if Kind were Utc.


The ToLocalTime method converts a DateTime value from UTC to local time. To convert the time in any designated time zone to local time, use the TimeZoneInfo::ConvertTime method.

The value returned by the conversion is a DateTime whose Kind property always returns Local. Consequently, a valid result is returned even if ToLocalTime is applied repeatedly to the same DateTime.

Notes to Callers:

You can use the ToLocalTime method to restore a local date and time value that was converted to UTC by the ToUniversalTime or FromFileTimeUtc method. However, if the original time represents an invalid time in the local time zone, it will not match the restored value. When the ToLocalTime method converts a time from UTC to the local time zone, it also adjusts the time so that is valid in the local time zone.

For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to UTC by the ToUniversalTime method and is then restored by the ToLocalTime method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the TimeZoneInfo::IsInvalidTime method, as the example illustrates.

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

The following example demonstrates the ToLocalTime method. Note that the exact output depends on the current culture and the local time zone of the system on which it is run.

using namespace System;

void main()
   Console::WriteLine("Enter a date and time.");
   String^ strDateTime = Console::ReadLine();

   DateTime localDateTime, univDateTime;
      localDateTime = DateTime::Parse(strDateTime);
      univDateTime = localDateTime.ToUniversalTime();

      Console::WriteLine("{0} local time is {1} universal time.",
                         localDateTime, univDateTime );
   catch (FormatException^) 
      Console::WriteLine("Invalid format.");

   Console::WriteLine("Enter a date and time in universal time.");
   strDateTime = Console::ReadLine();

      univDateTime = DateTime::Parse(strDateTime);
      localDateTime = univDateTime.ToLocalTime();

      Console::WriteLine("{0} universal time is {1} local time.",
                         univDateTime, localDateTime );
   catch (FormatException^) 
      Console::WriteLine("Invalid format.");
// The example displays output like the following when run on a 
// computer whose culture is en-US in the Pacific Standard Time zone:
//     Enter a date and time.
//     12/10/2015 6:18 AM
//     12/10/2015 6:18:00 AM local time is 12/10/2015 2:18:00 PM universal time.
//     Enter a date and time in universal time.
//     12/20/2015 6:42:00
//     12/20/2015 6:42:00 AM universal time is 12/19/2015 10:42:00 PM local time.

The following example uses the SpecifyKind method to demonstrate how the Kind property influences the ToLocalTime and ToUniversalTime conversion methods.

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
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