Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
zoneinfo
communitycreator

What is zoneinfo.available_timezones() in Python?

Gutha Vamsi Krishna

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

The zoneinfo module provides the available_timezones() function to get a set of all of the available time zones present in your system’s IANA database.

  • This set is recalculated for every call to the function.
  • The list may vary from system to system.
  • These are the keys that are passed to the ZoneInfo( key ) constructor.

Note: The zoneinfo module is only available in Python version 3.9 or higher.

Syntax

zoneinfo.available_timezones()

Parameters

This function does not accept any parameters.

Return value

The function returns a set of available time zones in the IANA database.

Example

In the example below, we:

  • Import zoneinfo.
  • Loop through the list returned by zoneinfo.available_timezones() and print out the timezones.
import zoneinfo
for key in zoneinfo.available_timezones():
print(key)

RELATED TAGS

python
zoneinfo
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring