Skip to content

Instantly share code, notes, and snippets.

@k0001
Created April 4, 2009 01:45
Show Gist options
  • Save k0001/90079 to your computer and use it in GitHub Desktop.
Save k0001/90079 to your computer and use it in GitHub Desktop.
import datetime
import locale
def utc_datetime_from_twitter_string_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, u'%a %b %d %H:%M:%S +0000 %Y')
finally:
locale.setlocale(locale.LC_ALL, prev_loc)
utc_datetime_from_twitter_string_timestamp(u'Fri Apr 03 16:08:49 +0000 2009')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment