java中如何处理夏令时?

2022-11-18 16:00:42 浏览数 (1)

在国际化的项目中,处理时间时经常会遇到夏令时(BST,British Summer Time)问题,发明夏令时(以及冬令时)主要是为了省电。

冷知识:中国历史上也曾经采用过(1986-1991)夏令时,后来因为各种原因,最终取消了这一制度(参见:https://baijiahao.baidu.com/s?id=1700703328355099602&wfr=spider&for=pc)

但欧美国家仍在广泛使用,以2022年为例:根据网上找到的资料

http://www.timeofdate.com/city/United Kingdom/London/timezone/change

伦敦 在2022-03-27 ~ 2002-10-30 为夏令时期间。

java中如何知道某个地区,在某个时间点是否处于夏令时呢?

代码语言:javascript复制
/**
 * 夏令时测试(by菩提树下的杨过)
 */
@Test
public void testTimeZone() {
    LocalTime time = LocalTime.of(10, 20);
    ZoneId zoneId = ZoneId.of("Europe/London");

    // A summer date-time
    ZonedDateTime zdtSummer = ZonedDateTime.of(LocalDate.of(2022, 10, 15), time, zoneId);
    System.out.println(zdtSummer);

    // A winter date-time
    ZonedDateTime zdtWinter = ZonedDateTime.of(LocalDate.of(2022, 11, 15), time, zoneId);
    System.out.println(zdtWinter);
}

输出:

代码语言:javascript复制
2022-10-15T10:20 01:00[Europe/London]
2022-11-15T10:20Z     [Europe/London]

即:2022-10-15 10:20:00 这个时间,对于London来说,时区的offset为 1,即向前拨快了1小时(夏令时)

而2022-11-15 10:20:00 这个时间,London的时区offset为Z(即Zero 零),即没有向前调整(不是夏令时)

通过这个测试,可以看到JDK里已经自带了夏令时的判断。

那么问题来了,ZoneId在构建时,要传入“Europe/London”这样的地区标识,JDK里支持多少种这类地区标识呢?

代码语言:javascript复制
/**
 * 输出全球所有时区(by菩提树下的杨过)
 */
@Test
public void getAvailableZoneIds() {
    Calendar c = Calendar.getInstance();
    System.out.println("year:"   c.get(Calendar.YEAR)   ",month:"   (c.get(Calendar.MONTH)   1)   ",day:"   c.get(Calendar.DAY_OF_MONTH)   "n");
    TreeMap<String, String> result = new TreeMap<>();
    //遍历所有ZoneId,并以今天9点时刻做为依赖,打印出每个ZoneId对应的时区
    for (String strZoneId : ZoneId.getAvailableZoneIds()) {
        LocalTime time = LocalTime.of(9, 0);
        ZoneId zoneId = ZoneId.of(strZoneId);
        ZonedDateTime zonedDateTime = ZonedDateTime.of(LocalDate.of(c.get(Calendar.YEAR), c.get(Calendar.MONTH)   1, c.get(Calendar.DAY_OF_MONTH)), time, zoneId);
        String offSet = zonedDateTime.getOffset().toString().split(":")[0];
        if ("Z".equalsIgnoreCase(offSet)) {
            offSet = " 0";
        } else {
            int temp = Integer.valueOf(offSet);
            if (temp > 0) {
                offSet = " "   temp;
            } else {
                offSet = ""   temp;
            }
        }
        result.put(strZoneId, "GMT"   offSet);
    }
    for (Map.Entry<String, String> entry : result.entrySet()) {
        System.out.println(entry.getValue()   "t"   entry.getKey());
    }
}

输出:

代码语言:javascript复制
year:2022,month:11,day:13

GMT 0	Africa/Abidjan
GMT 0	Africa/Accra
GMT 3	Africa/Addis_Ababa
GMT 1	Africa/Algiers
GMT 3	Africa/Asmara
GMT 3	Africa/Asmera
GMT 0	Africa/Bamako
GMT 1	Africa/Bangui
GMT 0	Africa/Banjul
GMT 0	Africa/Bissau
GMT 2	Africa/Blantyre
GMT 1	Africa/Brazzaville
GMT 2	Africa/Bujumbura
GMT 2	Africa/Cairo
GMT 1	Africa/Casablanca
GMT 1	Africa/Ceuta
GMT 0	Africa/Conakry
GMT 0	Africa/Dakar
GMT 3	Africa/Dar_es_Salaam
GMT 3	Africa/Djibouti
GMT 1	Africa/Douala
GMT 1	Africa/El_Aaiun
GMT 0	Africa/Freetown
GMT 2	Africa/Gaborone
GMT 2	Africa/Harare
GMT 2	Africa/Johannesburg
GMT 3	Africa/Juba
GMT 3	Africa/Kampala
GMT 2	Africa/Khartoum
GMT 2	Africa/Kigali
GMT 1	Africa/Kinshasa
GMT 1	Africa/Lagos
GMT 1	Africa/Libreville
GMT 0	Africa/Lome
GMT 1	Africa/Luanda
GMT 2	Africa/Lubumbashi
GMT 2	Africa/Lusaka
GMT 1	Africa/Malabo
GMT 2	Africa/Maputo
GMT 2	Africa/Maseru
GMT 2	Africa/Mbabane
GMT 3	Africa/Mogadishu
GMT 0	Africa/Monrovia
GMT 3	Africa/Nairobi
GMT 1	Africa/Ndjamena
GMT 1	Africa/Niamey
GMT 0	Africa/Nouakchott
GMT 0	Africa/Ouagadougou
GMT 1	Africa/Porto-Novo
GMT 1	Africa/Sao_Tome
GMT 0	Africa/Timbuktu
GMT 2	Africa/Tripoli
GMT 1	Africa/Tunis
GMT 2	Africa/Windhoek
GMT-10	America/Adak
GMT-9	America/Anchorage
GMT-4	America/Anguilla
GMT-4	America/Antigua
GMT-3	America/Araguaina
GMT-3	America/Argentina/Buenos_Aires
GMT-3	America/Argentina/Catamarca
GMT-3	America/Argentina/ComodRivadavia
GMT-3	America/Argentina/Cordoba
GMT-3	America/Argentina/Jujuy
GMT-3	America/Argentina/La_Rioja
GMT-3	America/Argentina/Mendoza
GMT-3	America/Argentina/Rio_Gallegos
GMT-3	America/Argentina/Salta
GMT-3	America/Argentina/San_Juan
GMT-3	America/Argentina/San_Luis
GMT-3	America/Argentina/Tucuman
GMT-3	America/Argentina/Ushuaia
GMT-4	America/Aruba
GMT-3	America/Asuncion
GMT-5	America/Atikokan
GMT-10	America/Atka
GMT-3	America/Bahia
GMT-6	America/Bahia_Banderas
GMT-4	America/Barbados
GMT-3	America/Belem
GMT-6	America/Belize
GMT-4	America/Blanc-Sablon
GMT-4	America/Boa_Vista
GMT-5	America/Bogota
GMT-7	America/Boise
GMT-3	America/Buenos_Aires
GMT-7	America/Cambridge_Bay
GMT-3	America/Campo_Grande
GMT-5	America/Cancun
GMT-4	America/Caracas
GMT-3	America/Catamarca
GMT-3	America/Cayenne
GMT-5	America/Cayman
GMT-6	America/Chicago
GMT-7	America/Chihuahua
GMT-5	America/Coral_Harbour
GMT-3	America/Cordoba
GMT-6	America/Costa_Rica
GMT-7	America/Creston
GMT-3	America/Cuiaba
GMT-4	America/Curacao
GMT 0	America/Danmarkshavn
GMT-8	America/Dawson
GMT-7	America/Dawson_Creek
GMT-7	America/Denver
GMT-5	America/Detroit
GMT-4	America/Dominica
GMT-7	America/Edmonton
GMT-5	America/Eirunepe
GMT-6	America/El_Salvador
GMT-8	America/Ensenada
GMT-7	America/Fort_Nelson
GMT-5	America/Fort_Wayne
GMT-3	America/Fortaleza
GMT-4	America/Glace_Bay
GMT-3	America/Godthab
GMT-4	America/Goose_Bay
GMT-5	America/Grand_Turk
GMT-4	America/Grenada
GMT-4	America/Guadeloupe
GMT-6	America/Guatemala
GMT-5	America/Guayaquil
GMT-4	America/Guyana
GMT-4	America/Halifax
GMT-5	America/Havana
GMT-7	America/Hermosillo
GMT-5	America/Indiana/Indianapolis
GMT-6	America/Indiana/Knox
GMT-5	America/Indiana/Marengo
GMT-5	America/Indiana/Petersburg
GMT-6	America/Indiana/Tell_City
GMT-5	America/Indiana/Vevay
GMT-5	America/Indiana/Vincennes
GMT-5	America/Indiana/Winamac
GMT-5	America/Indianapolis
GMT-7	America/Inuvik
GMT-5	America/Iqaluit
GMT-5	America/Jamaica
GMT-3	America/Jujuy
GMT-9	America/Juneau
GMT-5	America/Kentucky/Louisville
GMT-5	America/Kentucky/Monticello
GMT-6	America/Knox_IN
GMT-4	America/Kralendijk
GMT-4	America/La_Paz
GMT-5	America/Lima
GMT-8	America/Los_Angeles
GMT-5	America/Louisville
GMT-4	America/Lower_Princes
GMT-3	America/Maceio
GMT-6	America/Managua
GMT-4	America/Manaus
GMT-4	America/Marigot
GMT-4	America/Martinique
GMT-6	America/Matamoros
GMT-7	America/Mazatlan
GMT-3	America/Mendoza
GMT-6	America/Menominee
GMT-6	America/Merida
GMT-9	America/Metlakatla
GMT-6	America/Mexico_City
GMT-3	America/Miquelon
GMT-4	America/Moncton
GMT-6	America/Monterrey
GMT-3	America/Montevideo
GMT-5	America/Montreal
GMT-4	America/Montserrat
GMT-5	America/Nassau
GMT-5	America/New_York
GMT-5	America/Nipigon
GMT-9	America/Nome
GMT-2	America/Noronha
GMT-6	America/North_Dakota/Beulah
GMT-6	America/North_Dakota/Center
GMT-6	America/North_Dakota/New_Salem
GMT-7	America/Ojinaga
GMT-5	America/Panama
GMT-5	America/Pangnirtung
GMT-3	America/Paramaribo
GMT-7	America/Phoenix
GMT-5	America/Port-au-Prince
GMT-4	America/Port_of_Spain
GMT-5	America/Porto_Acre
GMT-4	America/Porto_Velho
GMT-4	America/Puerto_Rico
GMT-3	America/Punta_Arenas
GMT-6	America/Rainy_River
GMT-6	America/Rankin_Inlet
GMT-3	America/Recife
GMT-6	America/Regina
GMT-6	America/Resolute
GMT-5	America/Rio_Branco
GMT-3	America/Rosario
GMT-8	America/Santa_Isabel
GMT-3	America/Santarem
GMT-3	America/Santiago
GMT-4	America/Santo_Domingo
GMT-2	America/Sao_Paulo
GMT-1	America/Scoresbysund
GMT-7	America/Shiprock
GMT-9	America/Sitka
GMT-4	America/St_Barthelemy
GMT-3	America/St_Johns
GMT-4	America/St_Kitts
GMT-4	America/St_Lucia
GMT-4	America/St_Thomas
GMT-4	America/St_Vincent
GMT-6	America/Swift_Current
GMT-6	America/Tegucigalpa
GMT-4	America/Thule
GMT-5	America/Thunder_Bay
GMT-8	America/Tijuana
GMT-5	America/Toronto
GMT-4	America/Tortola
GMT-8	America/Vancouver
GMT-4	America/Virgin
GMT-8	America/Whitehorse
GMT-6	America/Winnipeg
GMT-9	America/Yakutat
GMT-7	America/Yellowknife
GMT 8	Antarctica/Casey
GMT 7	Antarctica/Davis
GMT 10	Antarctica/DumontDUrville
GMT 11	Antarctica/Macquarie
GMT 5	Antarctica/Mawson
GMT 13	Antarctica/McMurdo
GMT-3	Antarctica/Palmer
GMT-3	Antarctica/Rothera
GMT 13	Antarctica/South_Pole
GMT 3	Antarctica/Syowa
GMT 0	Antarctica/Troll
GMT 6	Antarctica/Vostok
GMT 1	Arctic/Longyearbyen
GMT 3	Asia/Aden
GMT 6	Asia/Almaty
GMT 2	Asia/Amman
GMT 12	Asia/Anadyr
GMT 5	Asia/Aqtau
GMT 5	Asia/Aqtobe
GMT 5	Asia/Ashgabat
GMT 5	Asia/Ashkhabad
GMT 5	Asia/Atyrau
GMT 3	Asia/Baghdad
GMT 3	Asia/Bahrain
GMT 4	Asia/Baku
GMT 7	Asia/Bangkok
GMT 7	Asia/Barnaul
GMT 2	Asia/Beirut
GMT 6	Asia/Bishkek
GMT 8	Asia/Brunei
GMT 5	Asia/Calcutta
GMT 9	Asia/Chita
GMT 8	Asia/Choibalsan
GMT 8	Asia/Chongqing
GMT 8	Asia/Chungking
GMT 5	Asia/Colombo
GMT 6	Asia/Dacca
GMT 2	Asia/Damascus
GMT 6	Asia/Dhaka
GMT 9	Asia/Dili
GMT 4	Asia/Dubai
GMT 5	Asia/Dushanbe
GMT 2	Asia/Famagusta
GMT 2	Asia/Gaza
GMT 8	Asia/Harbin
GMT 2	Asia/Hebron
GMT 7	Asia/Ho_Chi_Minh
GMT 8	Asia/Hong_Kong
GMT 7	Asia/Hovd
GMT 8	Asia/Irkutsk
GMT 3	Asia/Istanbul
GMT 7	Asia/Jakarta
GMT 9	Asia/Jayapura
GMT 2	Asia/Jerusalem
GMT 4	Asia/Kabul
GMT 12	Asia/Kamchatka
GMT 5	Asia/Karachi
GMT 6	Asia/Kashgar
GMT 5	Asia/Kathmandu
GMT 5	Asia/Katmandu
GMT 9	Asia/Khandyga
GMT 5	Asia/Kolkata
GMT 7	Asia/Krasnoyarsk
GMT 8	Asia/Kuala_Lumpur
GMT 8	Asia/Kuching
GMT 3	Asia/Kuwait
GMT 8	Asia/Macao
GMT 8	Asia/Macau
GMT 11	Asia/Magadan
GMT 8	Asia/Makassar
GMT 8	Asia/Manila
GMT 4	Asia/Muscat
GMT 2	Asia/Nicosia
GMT 7	Asia/Novokuznetsk
GMT 7	Asia/Novosibirsk
GMT 6	Asia/Omsk
GMT 5	Asia/Oral
GMT 7	Asia/Phnom_Penh
GMT 7	Asia/Pontianak
GMT 9	Asia/Pyongyang
GMT 3	Asia/Qatar
GMT 6	Asia/Qyzylorda
GMT 6	Asia/Rangoon
GMT 3	Asia/Riyadh
GMT 7	Asia/Saigon
GMT 11	Asia/Sakhalin
GMT 5	Asia/Samarkand
GMT 9	Asia/Seoul
GMT 8	Asia/Shanghai
GMT 8	Asia/Singapore
GMT 11	Asia/Srednekolymsk
GMT 8	Asia/Taipei
GMT 5	Asia/Tashkent
GMT 4	Asia/Tbilisi
GMT 3	Asia/Tehran
GMT 2	Asia/Tel_Aviv
GMT 6	Asia/Thimbu
GMT 6	Asia/Thimphu
GMT 9	Asia/Tokyo
GMT 7	Asia/Tomsk
GMT 8	Asia/Ujung_Pandang
GMT 8	Asia/Ulaanbaatar
GMT 8	Asia/Ulan_Bator
GMT 6	Asia/Urumqi
GMT 10	Asia/Ust-Nera
GMT 7	Asia/Vientiane
GMT 10	Asia/Vladivostok
GMT 9	Asia/Yakutsk
GMT 6	Asia/Yangon
GMT 5	Asia/Yekaterinburg
GMT 4	Asia/Yerevan
GMT-1	Atlantic/Azores
GMT-4	Atlantic/Bermuda
GMT 0	Atlantic/Canary
GMT-1	Atlantic/Cape_Verde
GMT 0	Atlantic/Faeroe
GMT 0	Atlantic/Faroe
GMT 1	Atlantic/Jan_Mayen
GMT 0	Atlantic/Madeira
GMT 0	Atlantic/Reykjavik
GMT-2	Atlantic/South_Georgia
GMT 0	Atlantic/St_Helena
GMT-3	Atlantic/Stanley
GMT 11	Australia/ACT
GMT 10	Australia/Adelaide
GMT 10	Australia/Brisbane
GMT 10	Australia/Broken_Hill
GMT 11	Australia/Canberra
GMT 11	Australia/Currie
GMT 9	Australia/Darwin
GMT 8	Australia/Eucla
GMT 11	Australia/Hobart
GMT 11	Australia/LHI
GMT 10	Australia/Lindeman
GMT 11	Australia/Lord_Howe
GMT 11	Australia/Melbourne
GMT 11	Australia/NSW
GMT 9	Australia/North
GMT 8	Australia/Perth
GMT 10	Australia/Queensland
GMT 10	Australia/South
GMT 11	Australia/Sydney
GMT 11	Australia/Tasmania
GMT 11	Australia/Victoria
GMT 8	Australia/West
GMT 10	Australia/Yancowinna
GMT-5	Brazil/Acre
GMT-2	Brazil/DeNoronha
GMT-2	Brazil/East
GMT-4	Brazil/West
GMT 1	CET
GMT-6	CST6CDT
GMT-4	Canada/Atlantic
GMT-6	Canada/Central
GMT-5	Canada/Eastern
GMT-7	Canada/Mountain
GMT-3	Canada/Newfoundland
GMT-8	Canada/Pacific
GMT-6	Canada/Saskatchewan
GMT-8	Canada/Yukon
GMT-3	Chile/Continental
GMT-5	Chile/EasterIsland
GMT-5	Cuba
GMT 2	EET
GMT-5	EST5EDT
GMT 2	Egypt
GMT 0	Eire
GMT 0	Etc/GMT
GMT 0	Etc/GMT 0
GMT-1	Etc/GMT 1
GMT-10	Etc/GMT 10
GMT-11	Etc/GMT 11
GMT-12	Etc/GMT 12
GMT-2	Etc/GMT 2
GMT-3	Etc/GMT 3
GMT-4	Etc/GMT 4
GMT-5	Etc/GMT 5
GMT-6	Etc/GMT 6
GMT-7	Etc/GMT 7
GMT-8	Etc/GMT 8
GMT-9	Etc/GMT 9
GMT 0	Etc/GMT-0
GMT 1	Etc/GMT-1
GMT 10	Etc/GMT-10
GMT 11	Etc/GMT-11
GMT 12	Etc/GMT-12
GMT 13	Etc/GMT-13
GMT 14	Etc/GMT-14
GMT 2	Etc/GMT-2
GMT 3	Etc/GMT-3
GMT 4	Etc/GMT-4
GMT 5	Etc/GMT-5
GMT 6	Etc/GMT-6
GMT 7	Etc/GMT-7
GMT 8	Etc/GMT-8
GMT 9	Etc/GMT-9
GMT 0	Etc/GMT0
GMT 0	Etc/Greenwich
GMT 0	Etc/UCT
GMT 0	Etc/UTC
GMT 0	Etc/Universal
GMT 0	Etc/Zulu
GMT 1	Europe/Amsterdam
GMT 1	Europe/Andorra
GMT 4	Europe/Astrakhan
GMT 2	Europe/Athens
GMT 0	Europe/Belfast
GMT 1	Europe/Belgrade
GMT 1	Europe/Berlin
GMT 1	Europe/Bratislava
GMT 1	Europe/Brussels
GMT 2	Europe/Bucharest
GMT 1	Europe/Budapest
GMT 1	Europe/Busingen
GMT 2	Europe/Chisinau
GMT 1	Europe/Copenhagen
GMT 0	Europe/Dublin
GMT 1	Europe/Gibraltar
GMT 0	Europe/Guernsey
GMT 2	Europe/Helsinki
GMT 0	Europe/Isle_of_Man
GMT 3	Europe/Istanbul
GMT 0	Europe/Jersey
GMT 2	Europe/Kaliningrad
GMT 2	Europe/Kiev
GMT 3	Europe/Kirov
GMT 0	Europe/Lisbon
GMT 1	Europe/Ljubljana
GMT 0	Europe/London
GMT 1	Europe/Luxembourg
GMT 1	Europe/Madrid
GMT 1	Europe/Malta
GMT 2	Europe/Mariehamn
GMT 3	Europe/Minsk
GMT 1	Europe/Monaco
GMT 3	Europe/Moscow
GMT 2	Europe/Nicosia
GMT 1	Europe/Oslo
GMT 1	Europe/Paris
GMT 1	Europe/Podgorica
GMT 1	Europe/Prague
GMT 2	Europe/Riga
GMT 1	Europe/Rome
GMT 4	Europe/Samara
GMT 1	Europe/San_Marino
GMT 1	Europe/Sarajevo
GMT 4	Europe/Saratov
GMT 3	Europe/Simferopol
GMT 1	Europe/Skopje
GMT 2	Europe/Sofia
GMT 1	Europe/Stockholm
GMT 2	Europe/Tallinn
GMT 1	Europe/Tirane
GMT 2	Europe/Tiraspol
GMT 4	Europe/Ulyanovsk
GMT 2	Europe/Uzhgorod
GMT 1	Europe/Vaduz
GMT 1	Europe/Vatican
GMT 1	Europe/Vienna
GMT 2	Europe/Vilnius
GMT 4	Europe/Volgograd
GMT 1	Europe/Warsaw
GMT 1	Europe/Zagreb
GMT 2	Europe/Zaporozhye
GMT 1	Europe/Zurich
GMT 0	GB
GMT 0	GB-Eire
GMT 0	GMT
GMT 0	GMT0
GMT 0	Greenwich
GMT 8	Hongkong
GMT 0	Iceland
GMT 3	Indian/Antananarivo
GMT 6	Indian/Chagos
GMT 7	Indian/Christmas
GMT 6	Indian/Cocos
GMT 3	Indian/Comoro
GMT 5	Indian/Kerguelen
GMT 4	Indian/Mahe
GMT 5	Indian/Maldives
GMT 4	Indian/Mauritius
GMT 3	Indian/Mayotte
GMT 4	Indian/Reunion
GMT 3	Iran
GMT 2	Israel
GMT-5	Jamaica
GMT 9	Japan
GMT 12	Kwajalein
GMT 2	Libya
GMT 1	MET
GMT-7	MST7MDT
GMT-8	Mexico/BajaNorte
GMT-7	Mexico/BajaSur
GMT-6	Mexico/General
GMT 13	NZ
GMT 13	NZ-CHAT
GMT-7	Navajo
GMT 8	PRC
GMT-8	PST8PDT
GMT 14	Pacific/Apia
GMT 13	Pacific/Auckland
GMT 11	Pacific/Bougainville
GMT 13	Pacific/Chatham
GMT 10	Pacific/Chuuk
GMT-5	Pacific/Easter
GMT 11	Pacific/Efate
GMT 13	Pacific/Enderbury
GMT 13	Pacific/Fakaofo
GMT 13	Pacific/Fiji
GMT 12	Pacific/Funafuti
GMT-6	Pacific/Galapagos
GMT-9	Pacific/Gambier
GMT 11	Pacific/Guadalcanal
GMT 10	Pacific/Guam
GMT-10	Pacific/Honolulu
GMT-10	Pacific/Johnston
GMT 14	Pacific/Kiritimati
GMT 11	Pacific/Kosrae
GMT 12	Pacific/Kwajalein
GMT 12	Pacific/Majuro
GMT-9	Pacific/Marquesas
GMT-11	Pacific/Midway
GMT 12	Pacific/Nauru
GMT-11	Pacific/Niue
GMT 11	Pacific/Norfolk
GMT 11	Pacific/Noumea
GMT-11	Pacific/Pago_Pago
GMT 9	Pacific/Palau
GMT-8	Pacific/Pitcairn
GMT 11	Pacific/Pohnpei
GMT 11	Pacific/Ponape
GMT 10	Pacific/Port_Moresby
GMT-10	Pacific/Rarotonga
GMT 10	Pacific/Saipan
GMT-11	Pacific/Samoa
GMT-10	Pacific/Tahiti
GMT 12	Pacific/Tarawa
GMT 13	Pacific/Tongatapu
GMT 10	Pacific/Truk
GMT 12	Pacific/Wake
GMT 12	Pacific/Wallis
GMT 10	Pacific/Yap
GMT 1	Poland
GMT 0	Portugal
GMT 9	ROK
GMT 8	Singapore
GMT-4	SystemV/AST4
GMT-4	SystemV/AST4ADT
GMT-6	SystemV/CST6
GMT-6	SystemV/CST6CDT
GMT-5	SystemV/EST5
GMT-5	SystemV/EST5EDT
GMT-10	SystemV/HST10
GMT-7	SystemV/MST7
GMT-7	SystemV/MST7MDT
GMT-8	SystemV/PST8
GMT-8	SystemV/PST8PDT
GMT-9	SystemV/YST9
GMT-9	SystemV/YST9YDT
GMT 3	Turkey
GMT 0	UCT
GMT-9	US/Alaska
GMT-10	US/Aleutian
GMT-7	US/Arizona
GMT-6	US/Central
GMT-5	US/East-Indiana
GMT-5	US/Eastern
GMT-10	US/Hawaii
GMT-6	US/Indiana-Starke
GMT-5	US/Michigan
GMT-7	US/Mountain
GMT-8	US/Pacific
GMT-8	US/Pacific-New
GMT-11	US/Samoa
GMT 0	UTC
GMT 0	Universal
GMT 3	W-SU
GMT 0	WET
GMT 0	Zulu

从上面的输出可以看出,要表示中国北京时区对应的ZoneId,ZoneId并不是Asia/Beijing,而是Asia/Shanghai

jdk

0 人点赞