admin管理员组文章数量:1328031
I got UTC timestamps and want to display them for different timezones.
Maybe an example can clarify what I am trying to do:
Given the timestamp 1259431620000
those times should be displayed:
Atlanta 13:07
San Francisco 10:07
London 17:07
Sydney 04:07
The cities might change but I guess you get what I am looking for.
Is there a javascript library or a mon solution that deals with the daylight saving?
I all ready have a list of all the time zones.
As the daylight saving is an easy and mon problem I thought there might be a library or a script dealing with them.
Just in case you are interesting in the timezone table:
* GMT -11:00
o Apia
o Midway
o Niue
o Pago Pago
* GMT -10:00
o Fakaofo
o Hawaii Time
o Johnston
o Rarotonga
o Tahiti
* GMT -09:00
o (GMT-09:30) Marquesas
o Alaska Time
o Gambier
* GMT -08:00
o Pacific Time
o Pacific Time - Tijuana
o Pacific Time - Vancouver
o Pacific Time - Whitehorse
o Pitcairn
* GMT -07:00
o Mountain Time - Dawson Creek
o Mountain Time (America/Denver)
o Mountain Time - Edmonton
o Mountain Time - Hermosillo
o Mountain Time - Chihuahua, Mazatlan
o Mountain Time - Arizona
o Mountain Time - Yellowknife
* GMT -06:00
o Belize
o Central Time
o Costa Rica
o El Salvador
o Guatemala
o Managua
o Central Time - Mexico City
o Central Time - Regina
o Central Time (America/Tegucigalpa)
o Central Time - Winnipeg
o Easter Island
o Galapagos
* GMT -05:00
o Bogota
o Cayman
o Grand Turk
o Guayaquil
o Havana
o Eastern Time - Iqaluit
o Jamaica
o Lima
o Eastern Time - Montreal
o Nassau
o Eastern Time
o Panama
o Port-au-Prince
o Eastern Time - Toronto
* GMT -04:00
o (GMT-04:30) Caracas
o Anguilla
o Antigua
o Aruba
o Asuncion
o Barbados
o Boa Vista
o Campo Grande
o Cuiaba
o Curacao
o Dominica
o Grenada
o Guadeloupe
o Guyana
o Atlantic Time - Halifax
o La Paz
o Manaus
o Martinique
o Montserrat
o Port of Spain
o Porto Velho
o Puerto Rico
o Rio Branco
o Santiago
o Santo Domingo
o St. Kitts
o St. Lucia
o St. Thomas
o St. Vincent
o Thule
o Tortola
o Palmer
o Bermuda
o Stanley
* GMT -03:00
o Newfoundland Time - St. Johns
o Araguaina
o Buenos Aires
o Salvador
o Belem
o Cayenne
o Fortaleza
o Godthab
o Maceio
o Miquelon
o Montevideo
o Paramaribo
o Recife
o Sao Paulo
o Rothera
* GMT -02:00
o Noronha
o South Georgia
* GMT -01:00
o Scoresbysund
o Azores
o Cape Verde
o Abidjan
* GMT 00:00
o Accra
o Bamako
o Banjul
o Bissau
o Casablanca
o Conakry
o Dakar
o El Aaiun
o Freetown
o Lome
o Monrovia
o Nouakchott
o Ouagadougou
o Sao Tome
o Danmarkshavn
o Canary Islands
o Faeroe
o Reykjavik
o St Helena
o GMT (no daylight saving)
o Dublin
o Lisbon
o London
* GMT +01:00
o Algiers
o Bangui
o Brazzaville
o Ceuta
o Douala
o Kinshasa
o Lagos
o Libreville
o Luanda
o Malabo
o Ndjamena
o Niamey
o Porto-Novo
o Tunis
o Windhoek
o Amsterdam
o Andorra
o Central European Time
o Berlin
o Brussels
o Budapest
o Copenhagen
o Gibraltar
o Luxembourg
o Madrid
o Malta
o Monaco
o Oslo
o Paris
o Rome
o Stockholm
o Tirane
o Vaduz
o Vienna
o Warsaw
o Zurich
* GMT +02:00
o Blantyre
o Bujumbura
o Cairo
o Gaborone
o Harare
o Johannesburg
o Kigali
o Lubumbashi
o Lusaka
o Maputo
o Maseru
o Mbabane
o Tripoli
o Amman
o Beirut
o Damascus
o Gaza
o Jerusalem
o Nicosia
o Athens
o Bucharest
o Chisinau
o Helsinki
o Istanbul
o Moscow-01 - Kaliningrad
o Kiev
o Minsk
o Riga
o Sofia
o Tallinn
o Vilnius
* GMT +03:00
o Addis Ababa
o Asmera
o Dar es Salaam
o Djibouti
o Kampala
o Khartoum
o Mogadishu
o Nairobi
o Syowa
o Aden
o Baghdad
o Bahrain
o Kuwait
o Qatar
o Riyadh
o Moscow+00
o Antananarivo
o Comoro
o Mayotte
o (GMT+03:30) Tehran
* GMT +04:00
o Baku
o Dubai
o Muscat
o Tbilisi
o Yerevan
o Moscow+01 - Samara
o Mahe
o Mauritius
o Reunion
o (GMT+04:30) Kabul
* GMT +05:00
o Aqtau
o Aqtobe
o Ashgabat
o Dushanbe
o Karachi
o Tashkent
o Moscow+02 - Yekaterinburg
o Kerguelen
o Maldives
o (GMT+05:30) India Standard Time
o (GMT+05:30) Colombo
o (GMT+05:45) Katmandu
* GMT +06:00
o Mawson
o Vostok
o Almaty
o Bishkek
o Dhaka
o Moscow+03 - Omsk, Novosibirsk
o Thimphu
o Chagos
o (GMT+06:30) Rangoon
o (GMT+06:30) Cocos
* GMT +07:00
o Davis
o Bangkok
o Hovd
o Jakarta
o Moscow+04 - Krasnoyarsk
o Phnom Penh
o Hanoi
o Vientiane
o Christmas
* GMT +08:00
o Casey
o Brunei
o Choibalsan
o Hong Kong
o Moscow+05 - Irkutsk
o Kuala Lumpur
o Macau
o Makassar
o Manila
o China Time - Beijing
o Singapore
o Taipei
o Ulaanbaatar
o Western Time - Perth
* GMT +09:00
o Dili
o Jayapura
o Pyongyang
o Seoul
o Tokyo
o Moscow+06 - Yakutsk
o Palau
o (GMT+09:30) Central Time - Adelaide
o (GMT+09:30) Central Time - Darwin
* GMT +10:00
o Dumont D'Urville
o Moscow+07 - Yuzhno-Sakhalinsk
o Eastern Time - Brisbane
o Eastern Time - Hobart
o Eastern Time - Melbourne, Sydney
o Guam
o Port Moresby
o Saipan
o Truk
* GMT +11:00
o Moscow+08 - Magadan
o Efate
o Guadalcanal
o Kosrae
o Noumea
o Ponape
o (GMT+11:30) Norfolk
* GMT +12:00
o Moscow+09 - Petropavlovsk-Kamchatskiy
o Auckland
o Fiji
o Funafuti
o Kwajalein
o Majuro
o Nauru
o Tarawa
o Wake
o Wallis
* GMT +13:00
o Enderbury
o Tongatapu
o Kiritimati
Thanks in advance
I got UTC timestamps and want to display them for different timezones.
Maybe an example can clarify what I am trying to do:
Given the timestamp 1259431620000
those times should be displayed:
Atlanta 13:07
San Francisco 10:07
London 17:07
Sydney 04:07
The cities might change but I guess you get what I am looking for.
Is there a javascript library or a mon solution that deals with the daylight saving?
I all ready have a list of all the time zones.
As the daylight saving is an easy and mon problem I thought there might be a library or a script dealing with them.
Just in case you are interesting in the timezone table:
* GMT -11:00
o Apia
o Midway
o Niue
o Pago Pago
* GMT -10:00
o Fakaofo
o Hawaii Time
o Johnston
o Rarotonga
o Tahiti
* GMT -09:00
o (GMT-09:30) Marquesas
o Alaska Time
o Gambier
* GMT -08:00
o Pacific Time
o Pacific Time - Tijuana
o Pacific Time - Vancouver
o Pacific Time - Whitehorse
o Pitcairn
* GMT -07:00
o Mountain Time - Dawson Creek
o Mountain Time (America/Denver)
o Mountain Time - Edmonton
o Mountain Time - Hermosillo
o Mountain Time - Chihuahua, Mazatlan
o Mountain Time - Arizona
o Mountain Time - Yellowknife
* GMT -06:00
o Belize
o Central Time
o Costa Rica
o El Salvador
o Guatemala
o Managua
o Central Time - Mexico City
o Central Time - Regina
o Central Time (America/Tegucigalpa)
o Central Time - Winnipeg
o Easter Island
o Galapagos
* GMT -05:00
o Bogota
o Cayman
o Grand Turk
o Guayaquil
o Havana
o Eastern Time - Iqaluit
o Jamaica
o Lima
o Eastern Time - Montreal
o Nassau
o Eastern Time
o Panama
o Port-au-Prince
o Eastern Time - Toronto
* GMT -04:00
o (GMT-04:30) Caracas
o Anguilla
o Antigua
o Aruba
o Asuncion
o Barbados
o Boa Vista
o Campo Grande
o Cuiaba
o Curacao
o Dominica
o Grenada
o Guadeloupe
o Guyana
o Atlantic Time - Halifax
o La Paz
o Manaus
o Martinique
o Montserrat
o Port of Spain
o Porto Velho
o Puerto Rico
o Rio Branco
o Santiago
o Santo Domingo
o St. Kitts
o St. Lucia
o St. Thomas
o St. Vincent
o Thule
o Tortola
o Palmer
o Bermuda
o Stanley
* GMT -03:00
o Newfoundland Time - St. Johns
o Araguaina
o Buenos Aires
o Salvador
o Belem
o Cayenne
o Fortaleza
o Godthab
o Maceio
o Miquelon
o Montevideo
o Paramaribo
o Recife
o Sao Paulo
o Rothera
* GMT -02:00
o Noronha
o South Georgia
* GMT -01:00
o Scoresbysund
o Azores
o Cape Verde
o Abidjan
* GMT 00:00
o Accra
o Bamako
o Banjul
o Bissau
o Casablanca
o Conakry
o Dakar
o El Aaiun
o Freetown
o Lome
o Monrovia
o Nouakchott
o Ouagadougou
o Sao Tome
o Danmarkshavn
o Canary Islands
o Faeroe
o Reykjavik
o St Helena
o GMT (no daylight saving)
o Dublin
o Lisbon
o London
* GMT +01:00
o Algiers
o Bangui
o Brazzaville
o Ceuta
o Douala
o Kinshasa
o Lagos
o Libreville
o Luanda
o Malabo
o Ndjamena
o Niamey
o Porto-Novo
o Tunis
o Windhoek
o Amsterdam
o Andorra
o Central European Time
o Berlin
o Brussels
o Budapest
o Copenhagen
o Gibraltar
o Luxembourg
o Madrid
o Malta
o Monaco
o Oslo
o Paris
o Rome
o Stockholm
o Tirane
o Vaduz
o Vienna
o Warsaw
o Zurich
* GMT +02:00
o Blantyre
o Bujumbura
o Cairo
o Gaborone
o Harare
o Johannesburg
o Kigali
o Lubumbashi
o Lusaka
o Maputo
o Maseru
o Mbabane
o Tripoli
o Amman
o Beirut
o Damascus
o Gaza
o Jerusalem
o Nicosia
o Athens
o Bucharest
o Chisinau
o Helsinki
o Istanbul
o Moscow-01 - Kaliningrad
o Kiev
o Minsk
o Riga
o Sofia
o Tallinn
o Vilnius
* GMT +03:00
o Addis Ababa
o Asmera
o Dar es Salaam
o Djibouti
o Kampala
o Khartoum
o Mogadishu
o Nairobi
o Syowa
o Aden
o Baghdad
o Bahrain
o Kuwait
o Qatar
o Riyadh
o Moscow+00
o Antananarivo
o Comoro
o Mayotte
o (GMT+03:30) Tehran
* GMT +04:00
o Baku
o Dubai
o Muscat
o Tbilisi
o Yerevan
o Moscow+01 - Samara
o Mahe
o Mauritius
o Reunion
o (GMT+04:30) Kabul
* GMT +05:00
o Aqtau
o Aqtobe
o Ashgabat
o Dushanbe
o Karachi
o Tashkent
o Moscow+02 - Yekaterinburg
o Kerguelen
o Maldives
o (GMT+05:30) India Standard Time
o (GMT+05:30) Colombo
o (GMT+05:45) Katmandu
* GMT +06:00
o Mawson
o Vostok
o Almaty
o Bishkek
o Dhaka
o Moscow+03 - Omsk, Novosibirsk
o Thimphu
o Chagos
o (GMT+06:30) Rangoon
o (GMT+06:30) Cocos
* GMT +07:00
o Davis
o Bangkok
o Hovd
o Jakarta
o Moscow+04 - Krasnoyarsk
o Phnom Penh
o Hanoi
o Vientiane
o Christmas
* GMT +08:00
o Casey
o Brunei
o Choibalsan
o Hong Kong
o Moscow+05 - Irkutsk
o Kuala Lumpur
o Macau
o Makassar
o Manila
o China Time - Beijing
o Singapore
o Taipei
o Ulaanbaatar
o Western Time - Perth
* GMT +09:00
o Dili
o Jayapura
o Pyongyang
o Seoul
o Tokyo
o Moscow+06 - Yakutsk
o Palau
o (GMT+09:30) Central Time - Adelaide
o (GMT+09:30) Central Time - Darwin
* GMT +10:00
o Dumont D'Urville
o Moscow+07 - Yuzhno-Sakhalinsk
o Eastern Time - Brisbane
o Eastern Time - Hobart
o Eastern Time - Melbourne, Sydney
o Guam
o Port Moresby
o Saipan
o Truk
* GMT +11:00
o Moscow+08 - Magadan
o Efate
o Guadalcanal
o Kosrae
o Noumea
o Ponape
o (GMT+11:30) Norfolk
* GMT +12:00
o Moscow+09 - Petropavlovsk-Kamchatskiy
o Auckland
o Fiji
o Funafuti
o Kwajalein
o Majuro
o Nauru
o Tarawa
o Wake
o Wallis
* GMT +13:00
o Enderbury
o Tongatapu
o Kiritimati
Thanks in advance
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Oct 28, 2009 at 16:53 jantimonjantimon 38.2k23 gold badges126 silver badges193 bronze badges 2- Would it possible to set these times from the backend? and if so what language are you using? – Mike Valstar Commented Oct 28, 2009 at 23:48
- No it is a little bit more plex than just displaying times. It has to be solved with JS somehow – jantimon Commented Oct 29, 2009 at 8:12
7 Answers
Reset to default 4 +150A prehensive source for timezone information is the Olson list. It is widely used in the UNIX world, and also available in e.g. Python in the form of pytz. It appears that someone has created some code that makes it available in JavaScript also, as mentioned in an older SO question.
This seems to be pretty much exactly what you're looking for ;)
It's a bit long-winded but this looks like it should probably work...
http://www.onlineaspect./2007/06/08/auto-detect-a-time-zone-with-javascript/
Since timezone is basically just adding some hours integer, translating from UTC time to localized time is trivial.
So I guess what you really need is a list of all cities/countries and their respective timezones... ? or am I misunderstanding?
What exactly do you need to acplish?
I should point out that DST time rules change constantly and in some countries they change on a yearly basis. I would try to solve this approach server-side but if that isn't possible I would consider using Ajax to call back to the server to get the current time or DST offset for the user. Maintaining your own list of timezones and zone rule changes is going to be a hassle, especially if you have to deploy it. But if you have a zone rule database actually implementing the library should be trivial.
Here's a very rich javascript library 'DateJs' - It also supports DayLight saving.
http://www.datejs./
You could just mark the time as UTC and provide something like this;
2010-01-01 00:00 (UTC) get time locally
www.worldtimeserver. don't seem to have a service you can consume to specify location so the user would need to select their own. You could subscribe to the Time Zone Database but that's $400 per year.
It seems like what you're asking for is a list of daylight savings time rules. So, here is a list of countries that observe DST, and how they observe it:
http://www.timeanddate./time/dst2009.html
本文标签: javascriptHow to determine the localtime of a timestamp for different timezonesStack Overflow
版权声明:本文标题:javascript - How to determine the localtime of a timestamp for different timezones? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742237014a2438264.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论