Пример #1
0
        /// <summary>
        /// Enumerate the available time zones
        /// </summary>
        /// <returns>The list of known time zones</returns>
        public static TimeZoneInformation[] EnumZones()
        {
            if ( s_zones == null )
            {
                lock( s_lockZones )
                {
                    if ( s_zones == null )
                    {
                        List<TimeZoneInformation> zones = new List<TimeZoneInformation>();

                        using ( RegistryKey key =
                                    Registry.LocalMachine.OpenSubKey(
                                    @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones" ) )
                        {
                            string[] zoneNames = key.GetSubKeyNames();

                            foreach ( string zoneName in zoneNames )
                            {
                                using ( RegistryKey subKey = key.OpenSubKey( zoneName ) )
                                {
                                    TimeZoneInformation tzi = new TimeZoneInformation();
                                    tzi.m_name = zoneName;
                                    tzi.m_displayName = (string) subKey.GetValue( "Display" );
                                    tzi.m_standardName = (string) subKey.GetValue( "Std" );
                                    tzi.m_daylightName = (string) subKey.GetValue( "Dlt" );
                                    tzi.InitTzi( (byte[]) subKey.GetValue( "Tzi" ) );
                                    tzi.m_index = (int)(subKey.GetValue("Index", zones.Count + 1));
                                    zones.Add( tzi );
                                }
                            }
                        }

                        zones.Sort(CompareByTzOffset);
                        s_zones = zones.ToArray();
                    }
                }
            }

            return s_zones;
        }
Пример #2
0
 public static int CompareByTzOffset(TimeZoneInformation left, TimeZoneInformation right)
 {
     return right.Bias - left.Bias;
 }