Skip to content

Instantly share code, notes, and snippets.

@estebistec
Created November 5, 2013 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save estebistec/7324558 to your computer and use it in GitHub Desktop.
Save estebistec/7324558 to your computer and use it in GitHub Desktop.
yes, parsing utc datetimes works (!??!)
$ pip freeze -l
python-dateutil==1.5
pytz==2013.8
$ python
...
>>> from dateutil.parser import parse
>>> import datetime
>>> import pytz
>>> d = datetime.datetime.now(pytz.UTC)
>>> d
datetime.datetime(2013, 11, 5, 19, 14, 9, 142824, tzinfo=<UTC>)
>>> sz = '2013-11-05T19:14:09.142824Z'
>>> s = d.isoformat()
>>> s
'2013-11-05T19:14:09.142824+00:00'
>>> sz
'2013-11-05T19:14:09.142824Z'
>>> parse(s)
datetime.datetime(2013, 11, 5, 19, 14, 9, 142824, tzinfo=tzutc())
>>> parse(sz)
datetime.datetime(2013, 11, 5, 19, 14, 9, 142824, tzinfo=tzutc())
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment