I'm trying to wrap my head around different timezones. How can I run python in a given timezone (overriding the system's timezone)?
Asked
Active
Viewed 195 times
2
-
duplicate? http://stackoverflow.com/questions/1301493/setting-timezone-in-python?rq=1 – Håken Lid Feb 12 '16 at 17:03
-
@HåkenLid that changes the timezone from inside python. This changes it from outside. It's a subtle difference, but a noteworthy one I think. Also, this requires fewer steps. – Oin Feb 13 '16 at 00:00
1 Answers
1
You can use the TZ
environment variable:
$ python -c 'import time; print(time.tzname)'
('GMT', 'BST')
$ TZ='Europe/Stockholm' python -c 'import time; print(time.tzname)'
('CET', 'CEST')
The time
and datetime
modules will honor this.

Oin
- 6,951
- 2
- 31
- 55
-
It assumes a bash-like shell on a platform with `tzdata`. It won't work on Windows. – jfs Feb 13 '16 at 16:24