Local Time To Utc Time

  1. 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.
  2. Struct tm. gmtime (const timet. timer); Convert timet to tm as UTC time Uses the value pointed by timer to fill a tm structure with the values that represent the corresponding time, expressed as a UTC time (i.e., the time at the GMT timezone). For a local time alternative, see localtime.
  3. Universal Time to Local Time Conversion. Universal Time: Scale:00:0000:0500:1000:1500:2000:25. Is local time not Right? Input the time zone below to convert: ยป UTC to Worldwide Timezone Converters. Universal Time Offset: UTC +0.:: Local Time:: Search Time Zone Converters.
  1. Utc Time Zone Conversion Chart
  2. What Is Utc Time Zone
-->

To convert a timestamp from one time zone to another, you can use the CONVERTTZ function: - using named time zones SELECT CONVERTTZ( '2018-01-01 12:00:00', 'UTC', 'MET' ); - using offset time zones SELECT CONVERTTZ( '2018-01-01 12:00:00', '+00:00', '+10:00' ).

Serial days

Definition

Converts a date and time to Coordinated Universal Time (UTC).

Overloads

Utc time conversion
ConvertTimeToUtc(DateTime, TimeZoneInfo)

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

ConvertTimeToUtc(DateTime)

Converts the specified date and time to Coordinated Universal Time (UTC).

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

Parameters

Utc Time Zone Conversion Chart

sourceTimeZone
TimeZoneInfo

The time zone of dateTime.

Returns

DateTime

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

Exceptions

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

-or-

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

-or-

sourceTimeZone.IsInvalidDateTime(dateTime) returns true.

sourceTimeZone is null.

Examples

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.

Remarks

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.

See also

Applies to

Converts the specified date and time to Coordinated Universal Time (UTC).

Parameters

Returns

DateTime

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

Exceptions

TimeZoneInfo.Local.IsInvalidDateTime(dateTime) returns true.

Examples

The following example illustrates the conversion of time values whose Kind property is DateTimeKind.Utc, DateTimeKind.Local, and DateTimeKind.Unspecified, respectively. It also illustrates the conversion of ambiguous and invalid times.

Remarks

What Is Utc Time Zone

The exact conversion performed depends on the value of the Kind property of the dateTime parameter, as the following table shows.

DateTime.Kind propertyConversion
DateTimeKind.LocalConverts from local time to Coordinated Universal Time (UTC).
DateTimeKind.UnspecifiedAssumes dateTime is local time and converts from local time to UTC.
DateTimeKind.UtcReturns dateTime unchanged.

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

Note

If the current computer's local time zone includes multiple adjustment rules, this overload of the ConvertTimeToUtc method can return results that differ from the TimeZone.ToUniversalTime and DateTime.ToUniversalTime methods. TimeZone.ToUniversalTime always applies the current adjustment rule to time zone conversion, whether or not dateTime lies within its date range. And when executing on .NET Framework 3.5, DateTime.ToUniversalTime also applies the current adjustment rule to time zone conversion, whether or not dateTime lies within its date range.

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

See also