Is there an elegant way to display the current time in another time zone?
I would like to have something with the general spirit of:
cur = <Get the current time, perhaps datetime.datetime.now()>
print("Local time {}".format(cur))
print("Pacific time {}".format(<something like cur.tz('PST')>))
print("Israeli time {}".format(<something like cur.tz('IST')>))
One way, through the timezone setting of the C library, is
A simpler method:
You could use the pytz library:
This is my implementation:
I need time info all time time, so I have this neat .py script on my server that lets me just select and deselect what time zones I want to display in order of east->west.
It prints like this:
Here source code is one .py file on my github here: https://github.com/SpiRaiL/timezone Or the direct file link: https://raw.githubusercontent.com/SpiRaiL/timezone/master/timezone.py
In the file is a list like this: Just put a 'p' in the places you want printed. Put a 'h' for your own time zone if you want it specially marked.
You can check this question.
Or try using pytz. Here you can find an installation guide with some usage examples.