Export (0) Print
Expand All

TimeZoneInfo.ConvertTimeBySystemTimeZoneId Method (DateTimeOffset, String)

Converts a time to the time in another time zone based on the time zone's identifier.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static DateTimeOffset ConvertTimeBySystemTimeZoneId(
	DateTimeOffset dateTimeOffset,
	string destinationTimeZoneId
)

Parameters

dateTimeOffset
Type: System.DateTimeOffset
The date and time to convert.
destinationTimeZoneId
Type: System.String
The identifier of the destination time zone.

Return Value

Type: System.DateTimeOffset
The date and time in the destination time zone.

ExceptionCondition
ArgumentNullException

destinationTimeZoneId is null.

InvalidTimeZoneException

The time zone identifier was found but the registry data is corrupted.

SecurityException

The process does not have the permissions required to read from the registry key that contains the time zone information.

TimeZoneNotFoundException

The destinationTimeZoneId identifier was not found on the local system.

When performing the conversion, the ConvertTimeBySystemTimeZoneId method applies any adjustment rules in effect in the destinationTimeZoneId time zone.

This overload is identical to calling the ConvertTime(DateTime, TimeZoneInfo) method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time.

Because the dateTimeOffset parameter represents a date and time together with that time's offset from Coordinated Universal Time (UTC), it cannot represent either an ambiguous time or an invalid time.

This method retrieves the time zone whose identifier is specified by the destinationTimeZoneId parameter from the registry. It cannot retrieve a time zone object that is created using the CreateCustomTimeZone method. The destinationTimeZoneId parameter must correspond exactly to the time zone's registry key in length, but not in case, for a successful match to occur; that is, the comparison of destinationTimeZoneId with time zone identifiers is case-insensitive.

In converting the dateTimeOffset value to the time in the destination time zone, the method takes into account any adjustment rules in effect in the destination time zone.

If the conversion of dateTimeOffset results in a date and time value that is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue, this method returns DateTimeOffset.MinValue or DateTimeOffset.MaxValue, respectively.

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft