Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get timezones with utc offset

is there a module or public API that given the UTC offset returns a list of all timezones in that offset ?

For example given UTC+2 it returns the following list:
Africa/Blantyre Africa/Bujumbura
Africa/Cairo Africa/Gaborone
Africa/Harare Africa/Johannesburg
Africa/Juba Africa/Khartoum
Africa/Kigali Africa/Lubumbashi
Africa/Lusaka Africa/Maputo
Africa/Maseru Africa/Mbabane
Africa/Tripoli Africa/Windhoek
Asia/Amman Asia/Beirut
Asia/Damascus Asia/Famagusta
Asia/Gaza Asia/Hebron
Asia/Jerusalem Asia/Nicosia
Europe/Athens Europe/Bucharest
Europe/Chisinau Europe/Helsinki
Europe/Kaliningrad Europe/Kiev
Europe/Mariehamn Europe/Riga
Europe/Sofia Europe/Tallinn
Europe/Uzhgorod Europe/Vilnius
Europe/Zaporozhye

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Because of daylight savings, the result depends on the current time.

>>> for zone in sorted(zoneinfo.available_timezones()):
...     tz = zoneinfo.ZoneInfo(zone)
...     if datetime.datetime.now(tz).utcoffset() == datetime.timedelta(hours=2):
...         print(tz)
Africa/Blantyre
Africa/Bujumbura
Africa/Cairo
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Juba
Africa/Khartoum
Africa/Kigali
Africa/Lubumbashi
Africa/Lusaka
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Tripoli
Africa/Windhoek
Asia/Amman
Asia/Beirut
Asia/Damascus
Asia/Famagusta
Asia/Gaza
Asia/Hebron
Asia/Jerusalem
Asia/Nicosia
Asia/Tel_Aviv
EET
Egypt
Etc/GMT-2
Europe/Athens
Europe/Bucharest
Europe/Chisinau
Europe/Helsinki
Europe/Kaliningrad
Europe/Kiev
Europe/Mariehamn
Europe/Nicosia
Europe/Riga
Europe/Sofia
Europe/Tallinn
Europe/Tiraspol
Europe/Uzhgorod
Europe/Vilnius
Europe/Zaporozhye
Israel
Libya

Python 3.9+ required for stdlib zoneinfo module.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading