Skip to content

Instantly share code, notes, and snippets.

@kirang89
Last active December 24, 2015 01:39
Show Gist options
  • Save kirang89/6725142 to your computer and use it in GitHub Desktop.
Save kirang89/6725142 to your computer and use it in GitHub Desktop.
Converting between UTC and local timezone
#!/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