Converts the value of the current DateTime object to local time.
An object whose DateTime.Kind property is DateTimeKind.Local, and whose value is the local time equivalent to the value of the current DateTime object, or DateTime.MaxValue if the converted value is too large to be represented by a DateTime object, or DateTime.MinValue if the converted value is too small to be represented as a DateTime object.
The local time is equal to the Coordinated Universal Time (UTC) time plus the UTC offset. For more information about the UTC offset, see TimeZone.GetUtcOffset(DateTime). The conversion also takes into account the daylight saving time rule that applies to the time represented by the current DateTime object.
On winxp systems, the DateTime.ToLocalTime method recognizes only the current adjustment rule when converting from UTC to local time. As a result, conversions for periods before the current adjustment rule came into effect may not accurately reflect the difference between UTC and local time.
Starting with the .NET Framework version 2.0, the value returned by the DateTime.ToLocalTime method is determined by the DateTime.Kind property of the current DateTime object. The following table describes the possible results.
DateTimeKind.Utc |
This instance of DateTime is converted to local time. |
DateTimeKind.Local |
No conversion is performed. |
DateTimeKind.Unspecified |
This instance of DateTime is assumed to be a UTC time, and the conversion is performed as if DateTime.Kind were DateTimeKind.Utc. |
The DateTime.ToLocalTime method converts a DateTime value from UTC to local time. To convert the time in any designated time zone to local time, use the TimeZoneInfo.ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) method.
The value returned by the conversion is a DateTime whose DateTime.Kind property always returns DateTimeKind.Local. Consequently, a valid result is returned even if DateTime.ToLocalTime is applied repeatedly to the same DateTime.