Created
August 12, 2019 09:19
-
-
Save cbonesana/6e57ee9cf590f57e3524dad9d1dfbd6e to your computer and use it in GitHub Desktop.
Just to remember how to convert UTC to GMT with time zones.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: https://stackoverflow.com/questions/5280692/python-convert-local-time-to-another-time-zone | |
from datetime import datetime | |
from pytz import timezone | |
format = '%Y-%m-%d %H:%M:%S' | |
now_utc = datetime.now(timezone('UTC')) | |
print(now_utc.strftime(format)) | |
# 2019-08-12 09:14:33 | |
now_gmt = now_utc.astimezone(timezone('Europe/Zurich')) | |
print(now_gmt.strftime(format)) | |
# 2019-08-12 11:14:33 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment