TimeZoneInfo.ConvertTimeToUtc Method (DateTime, TimeZoneInfo)


Converts the time in a specified time zone to Coordinated Universal Time (UTC).

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

Public Shared Function ConvertTimeToUtc (
	dateTime As Date,
	sourceTimeZone As TimeZoneInfo
) As Date


Type: System.DateTime

The date and time to convert.

Type: System.TimeZoneInfo

The time zone of dateTime.

Return Value

Type: System.DateTime

The Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. The DateTime object's Kind property is always set to DateTimeKind.Utc.

Exception Condition

dateTime.Kind is DateTimeKind.Utc and sourceTimeZone does not equal TimeZoneInfo.Utc.


dateTime.Kind is DateTimeKind.Local and sourceTimeZone does not equal TimeZoneInfo.Local.


sourceTimeZone.IsInvalidDateTime(dateTime) returns true.


sourceTimeZone is null.

If the Kind property of the dateTime parameter equals DateTimeKind.Utc and the sourceTimeZone parameter equals TimeZoneInfo.Utc, this method returns dateTime without performing any conversion.

If dateTime corresponds to an ambiguous time, this method assumes that it is the standard time of the source time zone. If dateTime corresponds to an invalid time, this method throws an ArgumentException.

If the Coordinated Universal Time (UTC) equivalent of dateTime is earlier than DateTime.MinValue or later that DateTime.MaxValue, this method returns MinValue or MaxValue, respectively.

Notes to Callers:

On Windows XP systems, the method applies only the current adjustment rule to the time zone conversion if sourceTimeZone is TimeZoneInfo.Local. As a result, the method may not accurately convert times for periods before the current adjustment rule came into effect. For more information, see the Notes for Callers section in the Local property.

The following example retrieves the current date from the local system and converts it to Coordinated Universal Time (UTC), then converts it to Tokyo Standard Time, and finally converts from Tokyo Standard Time back to UTC. Note that the two UTC times are identical.

Module Example
   Public Sub Main()
      ' Get time in local time zone 
      Dim thisTime As Date = Date.Now
      Console.WriteLine("Time in {0} zone: {1}", IIf(TimeZoneInfo.Local.IsDaylightSavingTime(thisTime), 
                        TimeZoneInfo.Local.DaylightName, TimeZoneInfo.Local.StandardName), thisTime)
      Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(thisTime, TimeZoneInfo.Local))
      ' Get Tokyo Standard Time zone
      Dim tst As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")
      Dim tstTime As Date = TimeZoneInfo.ConvertTime(thisTime, TimeZoneInfo.Local, tst)      
      Console.WriteLine("Time in {0} zone: {1}", IIf(tst.IsDaylightSavingTime(tstTime), 
                        tst.DaylightName, tst.StandardName), tstTime)
      Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(tstTime, tst))
   End Sub
End Module
' The example displays output like the following when run on a system in the U.S.
' Pacific Standard Time zone:
'    Time in Pacific Standard Time zone: 12/6/2013 10:57:51 AM
'       UTC Time: 12/6/2013 6:57:51 PM
'    Time in Tokyo Standard Time zone: 12/7/2013 3:57:51 AM
'       UTC Time: 12/6/2013 6:57:51 PM

.NET Framework
Available since 3.5
Return to top