Created
October 1, 2013 09:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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