Returns the local time that corresponds to a specified date and time value.
public:
virtual DateTime ToLocalTime(DateTime time);
public virtual DateTime ToLocalTime(DateTime time);
abstract member ToLocalTime : DateTime -> DateTime
override this.ToLocalTime : DateTime -> DateTime
Public Overridable Function ToLocalTime (time As DateTime) As DateTime
Parameters
A Coordinated Universal Time (UTC) time.
ReturnsA DateTime object whose value is the local time that corresponds to time
.
The following table shows the relationship between the time
parameter and the DateTime value returned by this method.
time
parameter Behavior Return value 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, ToLocalTime applies the current adjustment rule to time
when performing the conversion.
Note
The ToLocalTime 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 ToLocalTime method corresponds to the TimeZoneInfo.ConvertTimeFromUtc method with its destinationTimeZone
parameter set to TimeZoneInfo.Local. Whenever possible, use the TimeZoneInfo.ConvertTimeFromUtc method.
Although it is not required, in most cases derived classes should override the default implementation of this method. The behavior of the default implementation depends on the Kind property of the time
parameter. If its value is Local, this method returns time
unchanged. If its value is either Utc or Unspecified, this method assumes time
is UTC and converts it to the local system time without calling the GetUtcOffset(DateTime) method.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4