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.
Assembly: mscorlib (in mscorlib.dll)
static member CreateCustomTimeZone : id:string * baseUtcOffset:TimeSpan * displayName:string * standardDisplayName:string * daylightDisplayName:string * adjustmentRules:TimeZoneInfo.AdjustmentRule * disableDaylightSavingTime:bool -> TimeZoneInfo
The time zone's identifier.
A TimeSpan object that represents the time difference between this time zone and Coordinated Universal Time (UTC).
The display name of the new time zone.
The standard time name of the new time zone.
The daylight saving time name of the new time zone.
An array of TimeZoneInfo.AdjustmentRule objects that augment the base UTC offset for a particular period.
true to discard any daylight saving time-related information present in adjustmentRules with the new object; otherwise, false.
Return ValueType: System.TimeZoneInfo
The new time zone. If the disableDaylightSavingTime parameter is true, the returned object has no daylight saving time data.
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 themethod 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 object that are returned by the method call.method and the members of the
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.
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:
Calling the CreateAdjustmentRule method for each adjustment rule.
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 themethod 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.
Available since 3.5