Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the localtime of a timestamp for different timezones?

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 common 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 common 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

like image 536
jantimon Avatar asked Dec 20 '25 08:12

jantimon


2 Answers

A comprehensive 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 ;)

like image 108
Tuure Laurinolli Avatar answered Dec 21 '25 23:12

Tuure Laurinolli


It's a bit long-winded but this looks like it should probably work...

http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/

like image 28
IanR Avatar answered Dec 21 '25 22:12

IanR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!