Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TimeZoneInfo.CreateCustomTimeZone Method (String, TimeSpan, String, String)

Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, and a standard time display name.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public static TimeZoneInfo CreateCustomTimeZone(
	string id,
	TimeSpan baseUtcOffset,
	string displayName,
	string standardDisplayName
)

Parameters

id
Type: System.String

The time zone's identifier.

baseUtcOffset
Type: System.TimeSpan

An object that represents the time difference between this time zone and Coordinated Universal Time (UTC).

displayName
Type: System.String

The display name of the new time zone.

standardDisplayName
Type: System.String

The name of the new time zone's standard time.

Return Value

Type: System.TimeZoneInfo
The new time zone.
ExceptionCondition
ArgumentNullException

The id parameter is null.

ArgumentException

The id parameter is an empty string ("").

-or-

The baseUtcOffset parameter does not represent a whole number of minutes.

ArgumentOutOfRangeException

The baseUtcOffset parameter is greater than 14 hours or less than -14 hours.

This overload of the CreateCustomTimeZone(String, TimeSpan, String, String) method is suitable for creating a time zone that has no adjustments (that is, a time zone that does not support daylight saving time). To define a time zone that includes adjustments for daylight saving time, use either the TimeZoneInfo.CreateCustomTimeZone or the TimeZoneInfo.CreateCustomTimeZone method.

The following table shows the relationship between the parameters that are provided to the TimeZoneInfo.CreateCustomTimeZone method and the properties of the TimeZoneInfo object that are returned by the method call.

CreateCustomTimeZone parameter

TimeZoneInfo property

id

Id

baseUtcOffset

BaseUtcOffset

displayName

DisplayName

standardDisplayName

StandardName

Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the displayName parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example:

(GMT+02:00) Athens, Beirut, Istanbul, Minsk
(GMT-02:00) Mid-Atlantic
(GMT-07:00) Mountain Time (US & Canada)

The following example creates a custom time zone for the Mawson and Holme Bay regions of Antarctica. It then displays the result of converting the local time to the time in the new time zone.

string displayName = "(GMT+06:00) Antarctica/Mawson Time";
string standardName = "Mawson Time"; 
TimeSpan offset = new TimeSpan(06, 00, 00);
TimeZoneInfo mawson = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName);
Console.WriteLine("The current time is {0} {1}", 
                  TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, mawson),
                  mawson.StandardName);      

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.