Skip to content

Instantly share code, notes, and snippets.

@mozz100
Created October 1, 2013 09:13
Show Gist options
  • Save mozz100/6775835 to your computer and use it in GitHub Desktop.
Save mozz100/6775835 to your computer and use it in GitHub Desktop.
Get UTC timestamp in python. Is there a better way? This seems highly verbose.
from datetime import tzinfo, timedelta, datetime
import calendar
class UTC(tzinfo):
"""UTC"""
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return timedelta(0)
utc = UTC()
day = datetime(2012,6,6,tzinfo=utc)
print calendar.timegm(day.utctimetuple())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment