What value should I pass into TimeZoneInfo.FindSystemTimeZoneById(String)?

前端 未结 10 1916
南笙
南笙 2020-12-04 15:22

I want to use the TimeZoneInfo.FindSystemTimeZoneById(String) method, but I don\'t know what values to use as the input?

Where can I get a list of values for i

相关标签:
10条回答
  • 2020-12-04 15:41

    You can use that code below

    using System;
    
    namespace TimeZoneIds
    {
        class Program
        {
            static void Main(string[] args)
            {
                foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
                    Console.WriteLine(z.Id);
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-04 15:43

    Like others have said, you can find the list by iterating TimeZoneInfo.GetSystemTimeZones() to find the string you want to use. That said, if you only have information on the time difference (like GMT+9 or GMT-10 ) and cannot find your timezone after iterating the Timezones, you might want to see the following url to see which timezone do you need https://msdn.microsoft.com/en-US/library/ms912391(v=winembedded.11).aspx

    0 讨论(0)
  • 2020-12-04 15:47

    The available timezones are:

    Console.WriteLine(string.Join("\n",TimeZoneInfo.GetSystemTimeZones().Select(x=>x.Id)));
    

    Result:

    Dateline Standard Time
    UTC-11
    Aleutian Standard Time
    Hawaiian Standard Time
    Marquesas Standard Time
    Alaskan Standard Time
    UTC-09
    Pacific Standard Time (Mexico)
    UTC-08
    Pacific Standard Time
    US Mountain Standard Time
    Mountain Standard Time (Mexico)
    Mountain Standard Time
    Central America Standard Time
    Central Standard Time
    Easter Island Standard Time
    Central Standard Time (Mexico)
    Canada Central Standard Time
    SA Pacific Standard Time
    Eastern Standard Time (Mexico)
    Eastern Standard Time
    Haiti Standard Time
    Cuba Standard Time
    US Eastern Standard Time
    Paraguay Standard Time
    Atlantic Standard Time
    Venezuela Standard Time
    Central Brazilian Standard Time
    SA Western Standard Time
    Pacific SA Standard Time
    Turks And Caicos Standard Time
    Newfoundland Standard Time
    Tocantins Standard Time
    E. South America Standard Time
    SA Eastern Standard Time
    Argentina Standard Time
    Greenland Standard Time
    Montevideo Standard Time
    Saint Pierre Standard Time
    Bahia Standard Time
    UTC-02
    Mid-Atlantic Standard Time
    Azores Standard Time
    Cape Verde Standard Time
    UTC
    Morocco Standard Time
    GMT Standard Time
    Greenwich Standard Time
    W. Europe Standard Time
    Central Europe Standard Time
    Romance Standard Time
    Central European Standard Time
    W. Central Africa Standard Time
    Namibia Standard Time
    Jordan Standard Time
    GTB Standard Time
    Middle East Standard Time
    Egypt Standard Time
    E. Europe Standard Time
    Syria Standard Time
    West Bank Standard Time
    South Africa Standard Time
    FLE Standard Time
    Israel Standard Time
    Kaliningrad Standard Time
    Libya Standard Time
    Arabic Standard Time
    Turkey Standard Time
    Arab Standard Time
    Belarus Standard Time
    Russian Standard Time
    E. Africa Standard Time
    Iran Standard Time
    Arabian Standard Time
    Astrakhan Standard Time
    Azerbaijan Standard Time
    Russia Time Zone 3
    Mauritius Standard Time
    Georgian Standard Time
    Caucasus Standard Time
    Afghanistan Standard Time
    West Asia Standard Time
    Ekaterinburg Standard Time
    Pakistan Standard Time
    India Standard Time
    Sri Lanka Standard Time
    Nepal Standard Time
    Central Asia Standard Time
    Bangladesh Standard Time
    Omsk Standard Time
    Myanmar Standard Time
    SE Asia Standard Time
    Altai Standard Time
    W. Mongolia Standard Time
    North Asia Standard Time
    N. Central Asia Standard Time
    Tomsk Standard Time
    China Standard Time
    North Asia East Standard Time
    Singapore Standard Time
    W. Australia Standard Time
    Taipei Standard Time
    Ulaanbaatar Standard Time
    North Korea Standard Time
    Aus Central W. Standard Time
    Transbaikal Standard Time
    Tokyo Standard Time
    Korea Standard Time
    Yakutsk Standard Time
    Cen. Australia Standard Time
    AUS Central Standard Time
    E. Australia Standard Time
    AUS Eastern Standard Time
    West Pacific Standard Time
    Tasmania Standard Time
    Vladivostok Standard Time
    Lord Howe Standard Time
    Bougainville Standard Time
    Russia Time Zone 10
    Magadan Standard Time
    Norfolk Standard Time
    Sakhalin Standard Time
    Central Pacific Standard Time
    Russia Time Zone 11
    New Zealand Standard Time
    UTC+12
    Fiji Standard Time
    Kamchatka Standard Time
    Chatham Islands Standard Time
    Tonga Standard Time
    Samoa Standard Time
    Line Islands Standard Time
    
    0 讨论(0)
  • 2020-12-04 15:51

    A method to cnvert from one time zone to another:

    DateTime n = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(datetime, "sourceTimeZoneId", "destinationTimeZoneId");
    

    I'm on Win10, and I list Time Zone Id with time difference:

    Dateline Standard Time                  -12
    UTC-11                                  -11
    Hawaiian Standard Time                  -10
    Aleutian Standard Time                  -9
    Marquesas Standard Time                 -9
    UTC-09                                  -9
    Alaskan Standard Time                   -8
    UTC-08                                  -8
    Pacific Standard Time (Mexico)          -7
    Pacific Standard Time                   -7
    US Mountain Standard Time               -7
    Mountain Standard Time (Mexico)         -6
    Mountain Standard Time                  -6
    Central America Standard Time           -6
    Easter Island Standard Time             -6
    Canada Central Standard Time            -6
    Central Standard Time                   -5
    Central Standard Time (Mexico)          -5
    SA Pacific Standard Time                -5
    Eastern Standard Time (Mexico)          -5
    Eastern Standard Time                   -4
    Haiti Standard Time                     -4
    Cuba Standard Time                      -4
    US Eastern Standard Time                -4
    Turks And Caicos Standard Time          -4
    Paraguay Standard Time                  -4
    Venezuela Standard Time                 -4
    Central Brazilian Standard Time         -4
    SA Western Standard Time                -4
    Pacific SA Standard Time                -4
    Atlantic Standard Time                  -3
    Tocantins Standard Time                 -3
    E. South America Standard Time          -3
    SA Eastern Standard Time                -3
    Argentina Standard Time                 -3
    Montevideo Standard Time                -3
    Magallanes Standard Time                -3
    Bahia Standard Time                     -3
    Newfoundland Standard Time              -2
    Greenland Standard Time                 -2
    Saint Pierre Standard Time              -2
    UTC-02                                  -2
    Mid-Atlantic Standard Time              -1
    Cape Verde Standard Time                -1
    Azores Standard Time                    0
    UTC                                     0
    Greenwich Standard Time                 0
    Sao Tome Standard Time                  0
    GMT Standard Time                       +1
    Morocco Standard Time                   +1
    W. Central Africa Standard Time         +1
    W. Europe Standard Time                 +2
    Central Europe Standard Time            +2
    Romance Standard Time                   +2
    Central European Standard Time          +2
    Egypt Standard Time                     +2
    South Africa Standard Time              +2
    Kaliningrad Standard Time               +2
    Sudan Standard Time                     +2
    Libya Standard Time                     +2
    Namibia Standard Time                   +2
    Jordan Standard Time                    +3
    GTB Standard Time                       +3
    Middle East Standard Time               +3
    E. Europe Standard Time                 +3
    Syria Standard Time                     +3
    West Bank Standard Time                 +3
    FLE Standard Time                       +3
    Israel Standard Time                    +3
    Arabic Standard Time                    +3
    Turkey Standard Time                    +3
    Arab Standard Time                      +3
    Belarus Standard Time                   +3
    Russian Standard Time                   +3
    E. Africa Standard Time                 +3
    Iran Standard Time                      +4
    Arabian Standard Time                   +4
    Astrakhan Standard Time                 +4
    Azerbaijan Standard Time                +4
    Russia Time Zone 3                      +4
    Mauritius Standard Time                 +4
    Saratov Standard Time                   +4
    Georgian Standard Time                  +4
    Volgograd Standard Time                 +4
    Caucasus Standard Time                  +4
    Afghanistan Standard Time               +4
    West Asia Standard Time                 +5
    Ekaterinburg Standard Time              +5
    Pakistan Standard Time                  +5
    Qyzylorda Standard Time                 +5
    India Standard Time                     +5
    Sri Lanka Standard Time                 +5
    Nepal Standard Time                     +5
    Central Asia Standard Time              +6
    Bangladesh Standard Time                +6
    Omsk Standard Time                      +6
    Myanmar Standard Time                   +6
    SE Asia Standard Time                   +7
    Altai Standard Time                     +7
    W. Mongolia Standard Time               +7
    North Asia Standard Time                +7
    N. Central Asia Standard Time           +7
    Tomsk Standard Time                     +7
    China Standard Time                     +8
    North Asia East Standard Time           +8
    Singapore Standard Time                 +8
    W. Australia Standard Time              +8
    Taipei Standard Time                    +8
    Ulaanbaatar Standard Time               +8
    Aus Central W. Standard Time            +8
    Transbaikal Standard Time               +9
    Tokyo Standard Time                     +9
    North Korea Standard Time               +9
    Korea Standard Time                     +9
    Yakutsk Standard Time                   +9
    Cen. Australia Standard Time            +9
    AUS Central Standard Time               +9
    E. Australia Standard Time              +10
    AUS Eastern Standard Time               +10
    West Pacific Standard Time              +10
    Tasmania Standard Time                  +10
    Vladivostok Standard Time               +10
    Lord Howe Standard Time                 +10
    Bougainville Standard Time              +11
    Russia Time Zone 10                     +11
    Magadan Standard Time                   +11
    Norfolk Standard Time                   +11
    Sakhalin Standard Time                  +11
    Central Pacific Standard Time           +11
    Russia Time Zone 11                     +12
    New Zealand Standard Time               +12
    UTC+12                                  +12
    Fiji Standard Time                      +12
    Chatham Islands Standard Time           +12
    Kamchatka Standard Time                 +13
    UTC+13                                  +13
    Tonga Standard Time                     +13
    Samoa Standard Time                     +13
    Line Islands Standard Time              +14
    

    Code to get time difference:

    DateTime dt = Convert.ToDateTime("2020-04-17T09:00:00");
    Dictionary<string, int> zoneHour = new Dictionary<string, int>();
    var infos = TimeZoneInfo.GetSystemTimeZones();
    foreach (var info in infos)
    {
        zoneHour.Add(info.Id,
            TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, "UTC", info.Id).Subtract(dt).Hours
        );
    }
    
    var zoneHourOrder = zoneHour.OrderBy(z => z.Value);
    foreach (var kv in zoneHourOrder)
    {
        Console.WriteLine(kv.Key.PadRight(40) + (kv.Value > 0 ? "+" + kv.Value : kv.Value.ToString()));
    }
    
    0 讨论(0)
提交回复
热议问题