To get all timezones in python, you can make use of the pytz module. Here is an example code snippet that retrieves a list of all timezones:
main.py100 chars7 lines
The pytz.all_timezones
function returns a list containing the names of all available timezones. In the example code above, we loop through the list and print out each timezone. You can use this list to set the timezone for a datetime object. Here is an example:
main.py183 chars10 lines
In the above example, we get the timezone object for 'America/New_York' and then for the current time in that timezone using datetime.now()
.
gistlibby LogSnag