C# TimeZoneInfo CreateCustomTimeZone(String, TimeSpan, String, String)
Description
TimeZoneInfo CreateCustomTimeZone(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.
Syntax
TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String)
has the following syntax.
public static TimeZoneInfo CreateCustomTimeZone(
string id,// w w w .ja v a2s. c om
TimeSpan baseUtcOffset,
string displayName,
string standardDisplayName
)
Parameters
TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String)
has the following parameters.
id
- The time zone's identifier.baseUtcOffset
- An 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 name of the new time zone's standard time.
Returns
TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String)
method returns The new time zone.
Example
The following example creates a custom time zone.
/* ww w . j a va 2s . c om*/
using System;
public class MainClass{
public static void Main(String[] argv){
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);
}
}
The code above generates the following result.