C# TimeZone Problem

roker002

Commander
Registriert
Dez. 2007
Beiträge
2.115
Ich möchte gerne für eine bestimmte Zeit das Umstelldatum für Sommer und Winterzeit pro region herauslesen.

Mit TimeZoneInfo kann man leider nicht herauslesen, wann die Zeitumstellung passiert. Mit TimeZone schon. Leider kann man nicht TimeZone auf was anderes umstellen...

Mit TimeZoneInfo.GetAdjustmentRules() bekommt man auch keine gültige Werte. Zumindest keine die ich gesehen habe.

kann man da irgendwie tricksen?

MFG
 
Code:
foreach (var ti in TimeZoneInfo.GetSystemTimeZones())
{
    if (ti.SupportsDaylightSavingTime)
    {
        //Console.WriteLine(String.Concat("DaylightName: ", ti.DaylightName));
        //Console.WriteLine(String.Concat("DisplayName: ", ti.DisplayName));
        Console.WriteLine(String.Concat("StandardName: ", ti.StandardName));
        //Console.WriteLine(String.Concat("SupportsDaylightSavingTime: ", ti.SupportsDaylightSavingTime));
        Console.WriteLine(TimeZoneInfo.ConvertTimeFromUtc(dt, ti));
                        
        foreach (TimeZoneInfo.AdjustmentRule ar in ti.GetAdjustmentRules())
            Console.WriteLine("{0:10} {1:10}", ar.DateStart.ToString(), ar.DateEnd.ToString());
    }
}

hab trotzdem keine gültige Werte. Soweit man nachlesen konnte, stammen die Werte aus der Registry. In der Registry gibt es einfach viele diese Einträge nicht.
 
roker002 schrieb:
Code:
foreach (var ti in TimeZoneInfo.GetSystemTimeZones())
{
    if (ti.SupportsDaylightSavingTime)
    {
        //Console.WriteLine(String.Concat("DaylightName: ", ti.DaylightName));
        //Console.WriteLine(String.Concat("DisplayName: ", ti.DisplayName));
        Console.WriteLine(String.Concat("StandardName: ", ti.StandardName));
        //Console.WriteLine(String.Concat("SupportsDaylightSavingTime: ", ti.SupportsDaylightSavingTime));
        Console.WriteLine(TimeZoneInfo.ConvertTimeFromUtc(dt, ti));
                        
        foreach (TimeZoneInfo.AdjustmentRule ar in ti.GetAdjustmentRules())
            Console.WriteLine("{0:10} {1:10}", ar.DateStart.ToString(), ar.DateEnd.ToString());
    }
}

hab trotzdem keine gültige Werte. Soweit man nachlesen konnte, stammen die Werte aus der Registry. In der Registry gibt es einfach viele diese Einträge nicht.

lesen ist wohl echt nicht deine stärke :)
habs doch oben extra geschrieben, sogar mit link zur msdn, wo es auch nochmal in fett steht.
DU VERWENDEST DIE FALSCHEN PROPERTIES!!
DaylightTransitionStart und DaylightTransitionEnd ist was du suchst.
 
Zuletzt bearbeitet:
Ich habe schon gerschrieben, dass es nicht funktioniert, da nicht alle Daten in der Registry abgespeichert sind.
DaylightTransitionStart und DaylightTransitionEnd ist was du suchst.

die meisten Werte sind auf DateTime.min gestellt. Man kann damit nix anfangen.
 
Code:
namespace FooBar
{
    using System;
    using System.Globalization;
    using System.IO;
    using System.Text;

    static class Program
    {
        static int Main( string[] args )
        {
            StringBuilder builder = new StringBuilder();
            var zones = TimeZoneInfo.GetSystemTimeZones();
            foreach ( var zone in zones )
            {
                builder.Append( zone.DisplayName );
                builder.Append( "\r\n" );
                if ( zone.SupportsDaylightSavingTime )
                {
                    var rules = zone.GetAdjustmentRules();
                    foreach ( var rule in rules )
                    {
                        DateTime start = rule.DaylightTransitionStart.ToDateTime( 2011 );
                        DateTime end = rule.DaylightTransitionEnd.ToDateTime( 2011 );

                        string dates = string.Format( "{0} - {1}", start.ToString( "dd.MM HH:mm" ), end.ToString( "dd.MM HH:mm" ) );
                        builder.Append( dates );
                        builder.Append( "\r\n" );
                    }
                }

                builder.Append( "\r\n" );
            }

            byte[] data = Encoding.ASCII.GetBytes( builder.ToString() );
            var stream = File.Open( @"D:\timezones.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.Read );
            stream.Write( data, 0, data.Length );
            stream.Close();
            stream.Dispose();

            return 0;
        }

        public static DateTime ToDateTime( this TimeZoneInfo.TransitionTime tt, int year )
        {
            Calendar calendar = CultureInfo.CurrentCulture.Calendar;
            int startOfWeek = (tt.Week * 7) - 6;
            int firstDay = (int)calendar.GetDayOfWeek( new DateTime( year, tt.Month, 1 ) );
            int transitionDay;
            int dayOfWeek = (int)tt.DayOfWeek;

            if ( firstDay <= dayOfWeek )
            {
                transitionDay = startOfWeek + ( dayOfWeek - firstDay );
            }
            else
            {
                transitionDay = startOfWeek + (7 - firstDay + dayOfWeek);
            }

            if ( transitionDay > calendar.GetDaysInMonth( year, tt.Month ) )
            {
                transitionDay -= 7;
            }

            return new DateTime( year, tt.Month, transitionDay, tt.TimeOfDay.Hour, tt.TimeOfDay.Minute, 0 );
        }   
    }
}

Code:
(UTC) Casablanca
28.05 23:59 - 28.08 23:59
29.05 23:59 - 18.08 23:59
07.05 23:59 - 06.08 23:59
02.04 23:59 - 30.07 23:59

(UTC) Coordinated Universal Time

(UTC) Dublin, Edinburgh, Lisbon, London
27.03 01:00 - 30.10 02:00

(UTC) Monrovia, Reykjavik

(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
27.03 02:00 - 30.10 03:00

(UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
27.03 02:00 - 30.10 03:00

(UTC+01:00) Brussels, Copenhagen, Madrid, Paris
27.03 02:00 - 30.10 03:00

(UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb
27.03 02:00 - 30.10 03:00

(UTC+01:00) West Central Africa

(UTC+01:00) Windhoek
03.04 02:00 - 04.09 02:00
04.09 02:00 - 03.04 02:00

(UTC+02:00) Amman
31.03 00:00 - 30.09 01:00
31.03 23:59 - 28.10 01:00

(UTC+02:00) Athens, Bucharest
27.03 03:00 - 30.10 04:00

(UTC+02:00) Beirut
27.03 00:00 - 30.10 00:00
26.03 23:59 - 29.10 23:59
26.03 23:59 - 29.10 23:59
26.03 23:59 - 29.10 23:59
26.03 23:59 - 29.10 23:59
26.03 23:59 - 29.10 23:59
26.03 23:59 - 22.10 23:59
26.03 23:59 - 29.10 23:59
26.03 23:59 - 29.10 23:59
26.03 23:59 - 29.10 23:59
26.03 23:59 - 29.10 23:59
26.03 23:59 - 22.10 23:59
26.03 23:59 - 29.10 23:59

(UTC+02:00) Cairo
29.04 00:00 - 29.09 23:59
29.04 00:00 - 15.09 23:59
28.04 23:59 - 01.09 23:59
28.04 23:59 - 25.08 23:59
28.04 23:59 - 18.08 23:59
28.04 23:59 - 29.09 23:59

(UTC+02:00) Damascus
25.03 23:59 - 21.09 23:59
31.03 23:59 - 03.11 23:59
07.04 23:59 - 28.10 23:59
31.03 23:59 - 27.10 23:59
07.04 23:59 - 27.10 23:59
31.03 23:59 - 27.10 23:59
07.04 23:59 - 27.10 23:59
07.04 23:59 - 27.10 23:59
07.04 23:59 - 27.10 23:59
07.04 23:59 - 27.10 23:59
31.03 23:59 - 27.10 23:59
07.04 23:59 - 27.10 23:59

(UTC+02:00) Harare, Pretoria

(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
27.03 03:00 - 30.10 04:00

(UTC+02:00) Istanbul
27.03 03:00 - 30.10 04:00
28.03 03:00 - 30.10 04:00
27.03 03:00 - 30.10 04:00

(UTC+02:00) Jerusalem
01.04 02:00 - 09.10 02:00
25.03 02:00 - 02.10 02:00
25.03 02:00 - 18.09 02:00
25.03 02:00 - 02.10 02:00
25.03 02:00 - 25.09 02:00
25.03 02:00 - 11.09 02:00
01.04 02:00 - 02.10 02:00
25.03 02:00 - 25.09 02:00
25.03 02:00 - 11.09 02:00
25.03 02:00 - 25.09 02:00
25.03 02:00 - 18.09 02:00
01.04 02:00 - 09.10 02:00
25.03 02:00 - 25.09 02:00
25.03 02:00 - 18.09 02:00
25.03 02:00 - 02.10 02:00
25.03 02:00 - 25.09 02:00
25.03 02:00 - 11.09 02:00
01.04 02:00 - 02.10 02:00

(UTC+02:00) Nicosia
27.03 02:00 - 30.10 03:00

(UTC+03:00) Baghdad
03.04 03:00 - 02.10 04:00
03.04 03:00 - 03.10 04:00

(UTC+03:00) Kaliningrad, Minsk
27.03 02:00 - 30.10 03:00

(UTC+03:00) Kuwait, Riyadh

(UTC+03:00) Nairobi

(UTC+03:30) Tehran
06.03 02:00 - 27.09 02:00
17.03 23:59 - 17.09 23:59
19.03 23:59 - 19.09 23:59

(UTC+04:00) Abu Dhabi, Muscat

(UTC+04:00) Baku
27.03 04:00 - 30.10 05:00

(UTC+04:00) Moscow, St. Petersburg, Volgograd
27.03 02:00 - 30.10 03:00

(UTC+04:00) Port Louis
30.10 02:00 - 04.01 00:00
06.01 00:00 - 27.03 02:00

(UTC+04:00) Tbilisi

(UTC+04:00) Yerevan
27.03 02:00 - 30.10 03:00

(UTC+04:30) Kabul

(UTC+05:00) Islamabad, Karachi
28.05 23:59 - 28.10 23:59
12.04 23:59 - 29.10 23:59

(UTC+05:00) Tashkent

(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi

(UTC+05:30) Sri Jayawardenepura

(UTC+05:45) Kathmandu

(UTC+06:00) Astana

(UTC+06:00) Dhaka
17.06 23:00 - 29.12 23:59

(UTC+06:00) Ekaterinburg
27.03 02:00 - 30.10 03:00

(UTC+06:30) Yangon (Rangoon)

(UTC+07:00) Bangkok, Hanoi, Jakarta

(UTC+07:00) Novosibirsk
27.03 02:00 - 30.10 03:00

(UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi

(UTC+08:00) Krasnoyarsk
27.03 02:00 - 30.10 03:00

(UTC+08:00) Kuala Lumpur, Singapore

(UTC+08:00) Perth
04.12 02:00 - 02.01 00:00
30.10 02:00 - 27.03 03:00
30.10 02:00 - 27.03 03:00
06.01 00:00 - 27.03 03:00

(UTC+08:00) Taipei

(UTC+08:00) Ulaanbaatar

(UTC+09:00) Irkutsk
27.03 02:00 - 30.10 03:00

(UTC+09:00) Osaka, Sapporo, Tokyo

(UTC+09:00) Seoul

(UTC+09:30) Adelaide
30.10 02:00 - 27.03 03:00
02.10 02:00 - 03.04 03:00

(UTC+09:30) Darwin

(UTC+10:00) Brisbane

(UTC+10:00) Canberra, Melbourne, Sydney
30.10 02:00 - 27.03 03:00
02.10 02:00 - 03.04 03:00

(UTC+10:00) Guam, Port Moresby

(UTC+10:00) Hobart
02.10 02:00 - 27.03 03:00
02.10 02:00 - 03.04 03:00

(UTC+10:00) Yakutsk
27.03 02:00 - 30.10 03:00

(UTC+11:00) Solomon Is., New Caledonia

(UTC+11:00) Vladivostok
27.03 02:00 - 30.10 03:00

(UTC+12:00) Auckland, Wellington
02.10 02:00 - 20.03 03:00
25.09 02:00 - 20.03 03:00
25.09 02:00 - 03.04 03:00

(UTC+12:00) Coordinated Universal Time+12

(UTC+12:00) Fiji
27.11 02:00 - 06.01 00:00
23.10 02:00 - 27.03 03:00
23.10 02:00 - 06.03 03:00
23.10 02:00 - 23.01 03:00
23.10 02:00 - 06.03 03:00

(UTC+12:00) Magadan
27.03 02:00 - 30.10 03:00

(UTC+12:00) Petropavlovsk-Kamchatsky - Old
27.03 02:00 - 30.10 03:00

(UTC+13:00) Nuku'alofa

(UTC+13:00) Samoa
24.09 23:59 - 07.01 00:00
25.09 00:00 - 03.04 01:00

(UTC-01:00) Azores
27.03 02:00 - 30.10 03:00

(UTC-01:00) Cape Verde Is.

(UTC-02:00) Coordinated Universal Time-02

(UTC-02:00) Mid-Atlantic
27.03 02:00 - 25.09 02:00

(UTC-03:00) Brasilia
06.11 00:00 - 13.02 02:00
09.10 00:00 - 27.02 00:00
15.10 23:59 - 20.02 00:00
15.10 23:59 - 12.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 12.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59

(UTC-03:00) Buenos Aires
25.12 00:00 - 03.01 00:00
15.10 23:59 - 20.03 00:00
06.01 00:00 - 12.03 23:59

(UTC-03:00) Cayenne, Fortaleza

(UTC-03:00) Greenland
03.04 02:00 - 30.10 02:00
26.03 22:00 - 22.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 22.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 29.10 23:00
26.03 22:00 - 22.10 23:00
26.03 22:00 - 29.10 23:00

(UTC-03:00) Montevideo
11.09 02:00 - 13.03 02:00
02.10 02:00 - 13.03 02:00

(UTC-03:00) Salvador
15.10 23:59 - 01.01 00:00
15.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 12.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59

(UTC-03:30) Newfoundland
03.04 00:01 - 30.10 00:01
13.03 00:01 - 06.11 00:01
13.03 00:01 - 06.11 00:01
13.03 00:01 - 06.11 00:01
13.03 00:01 - 06.11 00:01
13.03 00:01 - 06.11 02:00
13.03 02:00 - 06.11 02:00

(UTC-04:00) Asuncion
15.10 23:59 - 12.03 23:59
15.10 23:59 - 05.03 23:59
01.10 23:59 - 09.04 23:59
01.10 23:59 - 09.04 23:59
01.10 23:59 - 02.04 23:59
01.10 23:59 - 09.04 23:59
01.10 23:59 - 09.04 23:59
01.10 23:59 - 09.04 23:59
01.10 23:59 - 09.04 23:59
24.09 23:59 - 09.04 23:59
01.10 23:59 - 02.04 23:59
01.10 23:59 - 09.04 23:59
01.10 23:59 - 09.04 23:59
01.10 23:59 - 09.04 23:59

(UTC-04:00) Atlantic Time (Canada)
03.04 02:00 - 30.10 02:00
13.03 02:00 - 06.11 02:00

(UTC-04:00) Cuiaba
06.11 00:00 - 13.02 02:00
09.10 00:00 - 27.02 00:00
15.10 23:59 - 20.02 00:00
15.10 23:59 - 12.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 12.02 23:59
15.10 23:59 - 19.02 23:59
08.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 19.02 23:59
15.10 23:59 - 26.02 23:59
15.10 23:59 - 19.02 23:59

(UTC-04:00) Georgetown, La Paz, Manaus, San Juan

(UTC-04:00) Santiago
08.10 23:59 - 12.03 23:59
08.10 23:59 - 26.03 23:59
08.10 23:59 - 12.03 23:59
08.10 23:59 - 02.04 23:59
20.08 23:59 - 07.05 23:59
08.10 23:59 - 12.03 23:59

(UTC-04:30) Caracas

(UTC-05:00) Bogota, Lima, Quito

(UTC-05:00) Eastern Time (US & Canada)
03.04 02:00 - 30.10 02:00
13.03 02:00 - 06.11 02:00

(UTC-05:00) Indiana (East)
03.04 02:00 - 30.10 02:00
13.03 02:00 - 06.11 02:00

(UTC-06:00) Central America

(UTC-06:00) Central Time (US & Canada)
03.04 02:00 - 30.10 02:00
13.03 02:00 - 06.11 02:00

(UTC-06:00) Guadalajara, Mexico City, Monterrey
03.04 02:00 - 30.10 02:00

(UTC-06:00) Saskatchewan

(UTC-07:00) Arizona

(UTC-07:00) Chihuahua, La Paz, Mazatlan
03.04 02:00 - 30.10 02:00

(UTC-07:00) Mountain Time (US & Canada)
03.04 02:00 - 30.10 02:00
13.03 02:00 - 06.11 02:00

(UTC-08:00) Baja California
03.04 02:00 - 30.10 02:00

(UTC-08:00) Pacific Time (US & Canada)
03.04 02:00 - 30.10 02:00
13.03 02:00 - 06.11 02:00

(UTC-09:00) Alaska
03.04 02:00 - 30.10 02:00
13.03 02:00 - 06.11 02:00

(UTC-10:00) Hawaii

(UTC-11:00) Coordinated Universal Time-11

(UTC-12:00) International Date Line West
 
Zurück
Oben