System.TimeZone.ToLocalTime Method

Returns the local time that corresponds to a specified date and time value.

Syntax

public virtual DateTime ToLocalTime (DateTime time)

Parameters

time
A Coordinated Universal Time (UTC) time.

Returns

A DateTime object whose value is the local time that corresponds to time.

Remarks

The following table shows the relationship between the time parameter and the DateTime value returned by this method.

A Coordinated Universal Time (UTC) time (DateTimeKind.Utc).

Converts the time from UTC to the local time.

A DateTime object whose value is the local time that corresponds to time.

A local time (DateTimeKind.Local).

No conversion necessary.

The same DateTime value represented by the time parameter.

An unspecified time (DateTimeKind.Unspecified).

Assumes that the time is UTC and converts it from UTC to the local time.

A DateTime object whose value is the local time that corresponds to time.

If the local time zone observes daylight saving time, TimeZone.ToLocalTime(DateTime) applies the current adjustment rule to time when performing the conversion.

Note:

   The TimeZone.ToLocalTime(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 local time corresponding to a particular UTC 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.ToLocalTime(DateTime) method corresponds to the TimeZoneInfo.ConvertTimeFromUtc(DateTime, TimeZoneInfo) method with its destinationTimeZone parameter set to TimeZoneInfo.Local. Whenever possible, use the TimeZoneInfo.ConvertTimeFromUtc(DateTime, TimeZoneInfo) method.

Requirements

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