CreateCustomTimeZone Method (String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[], Boolean)

TimeZoneInfo.CreateCustomTimeZone Method (String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[], Boolean)


Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, daylight saving time rules, and a value that indicates whether the returned object reflects daylight saving time information.

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

static member CreateCustomTimeZone : 
        id:string *
        baseUtcOffset:TimeSpan *
        displayName:string *
        standardDisplayName:string *
        daylightDisplayName:string *
        adjustmentRules:TimeZoneInfo.AdjustmentRule[] *
        disableDaylightSavingTime:bool -> TimeZoneInfo


Type: System.String

The time zone's identifier.

Type: System.TimeSpan

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

Type: System.String

The display name of the new time zone.

Type: System.String

The standard time name of the new time zone.

Type: System.String

The daylight saving time name of the new time zone.

Type: System.TimeZoneInfo.AdjustmentRule[]

An array of TimeZoneInfo.AdjustmentRule objects that augment the base UTC offset for a particular period.

Type: System.Boolean

true to discard any daylight saving time-related information present in adjustmentRules with the new object; otherwise, false.

Return Value

Type: System.TimeZoneInfo

The new time zone. If the disableDaylightSavingTime parameter is true, the returned object has no daylight saving time data.

Exception Condition

The id parameter is null.


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


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


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


The adjustment rules specified in the adjustmentRules parameter overlap.


The adjustment rules specified in the adjustmentRules parameter are not in chronological order.


One or more elements in adjustmentRules are null.


A date can have multiple adjustment rules applied to it.


The sum of the baseUtcOffset parameter and the TimeZoneInfo.AdjustmentRule.DaylightDelta value of one or more objects in the adjustmentRules array is greater than 14 hours or less than -14 hours.

You can use this overload of the TimeZoneInfo.CreateCustomTimeZone method to create a custom time zone whose support for daylight saving time can be determined by conditions at run time.

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

CreateCustomTimeZone parameter

TimeZoneInfo property










DaylightName if disableDaylightSavingTime is false; String.Empty if disableDaylightSavingTime is true.


An array of TimeZoneInfo.AdjustmentRule objects returned by the GetAdjustmentRules method if disableDaylightSavingTime is false; an empty array returned by the GetAdjustmentRules method if disableDaylightSavingTime is true.


Not SupportsDaylightSavingTime.

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)

A time zone's adjustment rules are defined by doing the following:

  1. Calling either the CreateFloatingDateRule or the CreateFixedDateRule method to define the starting and ending transition rules for each adjustment rule.

  2. Calling the CreateAdjustmentRule method for each adjustment rule.

  3. Assigning the adjustment rules to an array that can be passed as the adjustmentRules parameter.

If disableDaylightSavingTime parameter is false, the operation of this method is identical to the TimeZoneInfo.CreateCustomTimeZone overload. If disableDaylightSavingTime is true, the returned object includes no adjustment rules and a DaylightName property whose value is an empty string.

The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It sets the disableDaylightSavingTime parameter in the call to the TimeZoneInfo.CreateCustomTimeZone method to true. It then displays the new time zone's daylight saving time name, if one is present, and the number of adjustment rules to confirm that the new time zone has no daylight saving time information.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5
Return to top
© 2015 Microsoft