C# TimeZoneInfo CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[], Boolean)
Description
TimeZoneInfo CreateCustomTimeZone(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.
Syntax
TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[], Boolean)
has the following syntax.
public static TimeZoneInfo CreateCustomTimeZone(
string id,/*from w ww . j a v a 2s . c o m*/
TimeSpan baseUtcOffset,
string displayName,
string standardDisplayName,
string daylightDisplayName,
TimeZoneInfo.AdjustmentRule[] adjustmentRules,
bool disableDaylightSavingTime
)
Parameters
TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[], Boolean)
has the following parameters.
id
- The time zone's identifier.baseUtcOffset
- A TimeSpan object that represents the time difference between this time zone and Coordinated Universal Time (UTC).displayName
- The display name of the new time zone.standardDisplayName
- The standard time name of the new time zone.daylightDisplayName
- The daylight saving time name of the new time zone.adjustmentRules
- An array of TimeZoneInfo.AdjustmentRule objects that augment the base UTC offset for a particular period.disableDaylightSavingTime
- true to discard any daylight saving time-related information present in adjustmentRules with the new object; otherwise, false.
Returns
TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[], Boolean)
method returns The new time zone. If the disableDaylightSavingTime parameter is true,
the returned object has no daylight saving time data.
Example
The following example creates a custom time zone.
/* w w w. j ava2s.c o m*/
using System;
public class MainClass{
public static void Main(String[] argv){
TimeZoneInfo.TransitionTime startTransition, endTransition;
startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0),
10, 2, DayOfWeek.Sunday);
endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1,3, 0, 0),
3, 2, DayOfWeek.Sunday);
// Define adjustment rule
TimeSpan delta = new TimeSpan(1, 0, 0);
TimeZoneInfo.AdjustmentRule adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1),
DateTime.MaxValue.Date, delta, startTransition, endTransition);
TimeZoneInfo.AdjustmentRule[] adjustments = {adjustment};
// Define other custom time zone arguments
string displayName = "(GMT-04:00) myTimeZone Time";
string standardName = "myTimeZone Standard Time";
string daylightName = "myTimeZone Daylight Time";
TimeSpan offset = new TimeSpan(-4, 0, 0);
TimeZoneInfo myTimeZone = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName,
daylightName, adjustments, true);
Console.WriteLine(myTimeZone.StandardName);
Console.WriteLine(myTimeZone.SupportsDaylightSavingTime);
}
}
The code above generates the following result.