C# program to get a sorted collection of all the time zones (TimeZoneInfo.GetSystemTimeZones() Method)

C# TimeZoneInfo.GetSystemTimeZones() Method: Here, we are going to learn how to get a sorted collection of all the time zones in C#.Net?
Submitted by Nidhi, on May 19, 2021

The GetSystemTimeZones() method of TimeZoneInfo class is a static method and used to get a sorted collection of all the time zones about which information is available on the local system.

Syntax:

    ReadOnlyCollection<TimeZoneInfo> TimeZoneInfo.GetSystemTimeZones();

Parameter(s):

  • None

Return value:

This method returns a sorted collection of all the time zones.

Exception(s):

  • System.OutOfMemoryException
  • System.Security.SecurityException

Program:

The source code to get a sorted collection of all the time zones is given below. The given program is compiled and executed successfully.

using System;
using System.Globalization;
using System.Collections.ObjectModel;

class TimeZoneInfoDemo
{
    //Entry point of Program
    static public void Main()
    {
        //Create a collection to get list of time zone.
        ReadOnlyCollection<TimeZoneInfo> listOfTimeZones;

        listOfTimeZones = TimeZoneInfo.GetSystemTimeZones();

        Console.WriteLine("\nList of Time Zone:");
        foreach (TimeZoneInfo time_zone in listOfTimeZones)
        {
            Console.WriteLine("{0, 39}", time_zone.DaylightName);
        }
    }
}

Output:

List of Time Zone:
                 Dateline Daylight Time
                    Samoa Daylight Time
                 Hawaiian Daylight Time
                  Alaskan Daylight Time
                  Pacific Daylight Time
         Pacific Daylight Time (Mexico)
              US Mountain Daylight Time
        Mountain Daylight Time (Mexico)
                 Mountain Daylight Time
          Central America Daylight Time
                  Central Daylight Time
         Central Daylight Time (Mexico)
           Canada Central Daylight Time
               SA Pacific Daylight Time
                  Eastern Daylight Time
               US Eastern Daylight Time
                Venezuela Daylight Time
                 Paraguay Daylight Time
                 Atlantic Daylight Time
               SA Western Daylight Time
        Central Brazilian Daylight Time
               Pacific SA Daylight Time
             Newfoundland Daylight Time
         E. South America Daylight Time
                Argentina Daylight Time
               SA Eastern Daylight Time
                Greenland Daylight Time
               Montevideo Daylight Time
             Mid-Atlantic Daylight Time
                   Azores Daylight Time
               Cape Verde Daylight Time
                  Morocco Daylight Time
             Coordinated Universal Time
                      GMT Daylight Time
                Greenwich Daylight Time
                W. Europe Daylight Time
           Central Europe Daylight Time
                  Romance Daylight Time
         Central European Daylight Time
        W. Central Africa Daylight Time
                   Jordan Daylight Time
                      GTB Daylight Time
              Middle East Daylight Time
                    Egypt Daylight Time
             South Africa Daylight Time
                      FLE Daylight Time
                Jerusalem Daylight Time
                E. Europe Daylight Time
                  Namibia Daylight Time
                   Arabic Daylight Time
                     Arab Daylight Time
                  Russian Daylight Time
                E. Africa Daylight Time
                 Georgian Daylight Time
                     Iran Daylight Time
                  Arabian Daylight Time
               Azerbaijan Daylight Time
                Mauritius Daylight Time
                 Caucasus Daylight Time
              Afghanistan Daylight Time
             Ekaterinburg Daylight Time
                 Pakistan Daylight Time
                West Asia Daylight Time
                    India Daylight Time
                Sri Lanka Daylight Time
                    Nepal Daylight Time
          N. Central Asia Daylight Time
             Central Asia Daylight Time
                  Myanmar Daylight Time
                  SE Asia Daylight Time
               North Asia Daylight Time
                    China Daylight Time
          North Asia East Daylight Time
          Malay Peninsula Daylight Time
             W. Australia Daylight Time
                   Taipei Daylight Time
                    Tokyo Daylight Time
                    Korea Daylight Time
                  Yakutsk Daylight Time
           Cen. Australia Daylight Time
              AUS Central Daylight Time
             E. Australia Daylight Time
              AUS Eastern Daylight Time
             West Pacific Daylight Time
                 Tasmania Daylight Time
              Vladivostok Daylight Time
          Central Pacific Daylight Time
              New Zealand Daylight Time
                     Fiji Daylight Time
                Kamchatka Daylight Time
                    Tonga Daylight Time
Press any key to continue . . .

C# TimeZoneInfo Class Programs »


ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.