I have a system (developed in Python) that accepts datetime as string in VARIOUS formats and i have to parse them..Currently datetime string formats are :
Fri Sep 25 18:09:49 -0500 2009
2008-06-29T00:42:18.000Z
2011-07-16T21:46:39Z
1294989360
Now i want a generic parser that can convert any of these datetime formats in appropriate datetime object…
Otherwise, i have to go with parsing them individually. So please also provide method for parsing them individually (if there is no generic parser)..!!
As @TimPietzcker suggested, the dateutil package is the way to go, it handles the first 3 formats correctly and automatically:
The unixtime format it seems to hiccough on, but luckily the standard
datetime.datetimeis up for the task:It is rather easy to make a function out of this that handles all 4 formats: