🕕C# Time Zone

Generate the current local time from the server, using local time zone name in appsetting.json

TimeZoneInfo cities

        var timeZoneCities = TimeZoneInfo.GetSystemTimeZones();
        string combinedString = string.Join(Environment.NewLine, timeZoneCities);

TimeZoneInfo ids

        string timeZoneIdsCombinedString = "";

        foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
        {
            Console.WriteLine(z.Id);
            timeZoneIdsCombinedString = timeZoneIds + Environment.NewLine+ z.Id;
        }

// Australia Time Zone List

private List<Tuple<string, string, string>> AustraliaTimeZoneList()
{
    // JS name, JS City, .NET id
    var list = new List<Tuple<string, string, string>>{
        new Tuple<string,string,string>("Australian Western Standard Time", "Perth", "W. Australia Standard Time"),                     // +8
        new Tuple<string,string,string>("Australian Central Western Standard Time", "Eucla", "Aus Central W. Standard Time"),           // +8:45
        new Tuple<string,string,string>("Australian Central Standard Time", "Darwin", "AUS Central Standard Time"),                     // +9:30/+10:30
        new Tuple<string,string,string>("Australian Eastern Standard Time", "Brisbane", "E. Australia Standard Time"),                  // +10
        new Tuple<string,string,string>("Australian Central Daylight Time", "Adelaide", "Cen. Australia Standard Time"),                // +10:30
        new Tuple<string,string,string>("Australian Eastern Daylight Time", "Canberra/Melbourne/Sydney", "AUS Eastern Standard Time"),  // +11/+10
        new Tuple<string,string,string>("Lord Howe Daylight Time", "Lord Howe Island", "Lord Howe Standard Time")};                     // +11/+10

    return list;
}

Last updated

Was this helpful?