How do I get python to pick up the OS timezone change?

There is a function in the running python instance that I can call to say "Hey python, update what you know about the timezone information"? So let's say I open python and then change / etc / localtime. How can I get python to update to the new timezone? My goal is not to interfere with the TZ environment variable or / etc / localtime link directly, or use any OS specific commands. I would also like not to restart python. Is it possible?


source to share

2 answers

The answer I was looking for was time.tzset () :

>>> time.tzname[time.daylight]
>>> #Use dpkg-reconfigure tzdata
>>> time.tzset()
>>> time.tzname[time.daylight]




time and tzlocal :

>>> from datetime import datetime
>>> from tzlocal import get_localzone
>>> tz = get_localzone()
<DstTzInfo 'Europe/Warsaw' CEST+2:00:00 DST>




All Articles