DateTime::ToUniversalTime Method ()


Converts the value of the current DateTime object to Coordinated Universal Time (UTC).

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

DateTime ToUniversalTime()

Return Value

Type: System::DateTime

An object whose Kind property is Utc, and whose value is the UTC 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 by a DateTime object.

The Coordinated Universal Time (UTC) is equal to the local time minus 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 ToUniversalTime method recognizes only the current adjustment rule when converting from local time to UTC. As a result, conversions for periods before the current adjustment rule came into effect may not accurately reflect the difference between local time and UTC. 

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




No conversion is performed.


The current DateTime object is converted to UTC.


The current DateTime object is assumed to be a local time, and the conversion is performed as if Kind were Local.


The ToUniversalTime method converts a DateTime value from local time to UTC. To convert the time in a non-local time zone to UTC, use the TimeZoneInfo::ConvertTimeToUtc(DateTime, TimeZoneInfo^) method. To convert a time whose offset from UTC is known, use the ToUniversalTime method.

If the date and time instance value is an ambiguous time, this method assumes that it is a standard time. (An ambiguous time is one that can map either to a standard time or to a daylight saving time in the local time zone) If the date and time instance value is an invalid time, this method simply subtracts the local time from the local time zone's UTC offset to return UTC. (An invalid time is one that does not exist because of the application of daylight saving time adjustment rules.)

Notes to Callers:

The ToUniversalTime method is sometimes used to convert a local time to UTC. The ToLocalTime method is then called to restore the original local time. However, if the original time represents an invalid time in the local time zone, the two local time values will not be equal. For additional information and an example, see the ToLocalTime method.

On Windows XP systems, the ToUniversalTime method recognizes only the current adjustment rule for the local time zone, which it applies to all dates, including down-level dates (that is, dates that are earlier than the starting date of the current adjustment rule). Applications running on Windows XP that require historically accurate local date and time calculations must work around this behavior by using the FindSystemTimeZoneById method to retrieve a TimeZoneInfo object that corresponds to the local time zone and calling its TimeZoneInfo::ConvertTimeToUtc(DateTime, TimeZoneInfo^) method.

The following example illustrates the difference between the ToUniversalTime and TimeZoneInfo::ConvertTimeToUtc(DateTime, TimeZoneInfo^) methods on a Windows XP system in the U.S. Pacific Time zone. The first two method calls apply the current time zone adjustment rule (which went into effect in 2007) to a date in 2006. The current adjustment rule provides for the transition to daylight saving time on the second Sunday of March; the previous rule, which was in effect in 2006, provided for the transition to daylight saving time to occur on the first Sunday of April. Only the third method call accurately performs this historical date and time conversion.

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

The following example demonstrates the ToUniversalTime method.

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