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?
+3
ErlVolton
source
to share
2 answers
The answer I was looking for was time.tzset () :
>>> time.tzname[time.daylight]
'CDT'
>>> #Use dpkg-reconfigure tzdata
...
>>> time.tzset()
>>> time.tzname[time.daylight]
'EDT'
>>>
+2
ErlVolton
source
to share
time and tzlocal :
>>> from datetime import datetime
>>> from tzlocal import get_localzone
>>> tz = get_localzone()
>>> datetime.now(tz).tzinfo
<DstTzInfo 'Europe/Warsaw' CEST+2:00:00 DST>
+1
Johnathan kennedy
source
to share