Create time zone from identifier, offset from Coordinated Universal Time (UTC), name, a standard time name, a daylight saving time name, daylight saving time rules in CSharp
Description
The following code shows how to create time zone from identifier, offset from Coordinated Universal Time (UTC), name, a standard time name, a daylight saving time name, daylight saving time rules.
Example
/*from w w w. jav a2 s . 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.