Skip to content

Instantly share code, notes, and snippets.

@k0001
Created May 6, 2009 07:20
Show Gist options
  • Save k0001/107415 to your computer and use it in GitHub Desktop.
Save k0001/107415 to your computer and use it in GitHub Desktop.
def utc_datetime_from_twitter_timestamp(s):
"""Parses as datetime.datetime in UTC a string formated Twitter timestamp"""
# we must parse the date in an english locale (due to %a and %b)
prev_loc = locale.getlocale()
try:
locale.setlocale(locale.LC_ALL, 'C')
return datetime.datetime.strptime(s, '%a %b %d %H:%M:%S +0000 %Y')
finally:
locale.setlocale(locale.LC_ALL, prev_loc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment