So you want to convert a UTC date string to a unix timestamp ? e.g. “2011-08-08T12:10:20+0000″ This particular UTC date string was from a Facebook /feed.
1 2 3 4 | >>> import dateutil.parser >>> d = "2011-08-08T12:10:20+0000" >>> dateutil.parser.parse(d).strftime("%s") '1312823420' |
Enjoy!
Update:
If you’re having issues like the following:
1 | TypeError: iter() returned non-iterator of type '_timelex' |
Then more than like you’re using Python 2.x and dateutil 2.0 (as listed here) Just downgrade to the compatible Python 2.x version like so:
1 | $ easy_install python-dateutil==1.5 |