Skip to content

Instantly share code, notes, and snippets.

@baseboxorg
Forked from kirang89/local_timezone_getter.py
Last active August 29, 2015 14:06
Show Gist options
  • Save baseboxorg/e144474d83115e05d27d to your computer and use it in GitHub Desktop.
Save baseboxorg/e144474d83115e05d27d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
from dateutil import tz
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
#Get a naive datetime
utc = datetime.utcnow()
#Represent it as UTC time
utc = utc.replace(tzinfo=from_zone)
#Convert to local timezone
local = utc.astimezone(to_zone)
print "UTC: ", utc
print "LOCAL: ", local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment