Skip to content

Instantly share code, notes, and snippets.

@julienr
Created April 28, 2014 12:42
Show Gist options
  • Save julienr/11370676 to your computer and use it in GitHub Desktop.
Save julienr/11370676 to your computer and use it in GitHub Desktop.
convert_timestamp.py
"""Convert UTC timestamp to custom timezone"""
import datetime
import pytz
import sys
assert len(sys.argv) > 1, 'Usage : convert_timestamp <timestamp>'
utc = pytz.utc
zurich = pytz.timezone('Europe/Zurich')
utc_dt = datetime.datetime.fromtimestamp(float(sys.argv[1]), tz=utc)
dt = utc_dt.astimezone(zurich)
print dt.strftime('%Y-%m-%d %H:%M:%S %Z%z')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment