System.TimeZone.GetUtcOffset Method

Returns the Coordinated Universal Time (UTC) offset for the specified local time.

Syntax

public abstract TimeSpan GetUtcOffset (DateTime time)

Parameters

time
A date and time value.

Returns

The Coordinated Universal Time (UTC) offset from time.

Remarks

This method returns the offset, or difference, between the time parameter and Coordinated Universal Time (UTC). That is:

time = UTC + offset

The method interprets the time zone of time based on its DateTime.Kind property. If the value of the DateTime.Kind property is DateTimeKind.Local or DateTimeKind.Unspecified, the method returns the offset of the local time zone. If the value of the DateTime.Kind property is DateTimeKind.Utc, the method returns an offset equal to TimeSpan.Zero.

If the local time zone observes daylight saving time, TimeZone.GetUtcOffset(DateTime) applies the current adjustment rule to time when determining the offset of the local time zone. That is, the offset returned by TimeZone.GetUtcOffset(DateTime) reflects whether time falls in the time zone's standard time or its daylight saving time.

Note:

The TimeZone.GetUtcOffset(DateTime) method recognizes only the current daylight saving time adjustment rule for the local time zone. As a result, it is guaranteed to accurately return the UTC offset of a local time only during the period in which the latest adjustment rule is in effect. It may return inaccurate results if time is a historic date and time value that was subject to a previous adjustment rule.

The TimeZone.GetUtcOffset(DateTime) method corresponds to the TimeZoneInfo.GetUtcOffset(DateTime) method. Whenever possible, use the TimeZoneInfo.GetUtcOffset(DateTime) method.

Because the date and time value represented by time and this value's offset from UTC are not tightly coupled, a local or unspecified date and time value can return a different offset value when run on different computers or when run on the same computer under different time zones. If this behavior is undesirable, use a DateTimeOffset value instead. The DateTimeOffset data type tightly couples a date and time value with its offset from UTC.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0