Skip to content

Instantly share code, notes, and snippets.

@cbonesana
Created August 12, 2019 09:19
Show Gist options
  • Save cbonesana/6e57ee9cf590f57e3524dad9d1dfbd6e to your computer and use it in GitHub Desktop.
Save cbonesana/6e57ee9cf590f57e3524dad9d1dfbd6e to your computer and use it in GitHub Desktop.
Just to remember how to convert UTC to GMT with time zones.
# 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