PHP has the amazing strtotime() function which takes pretty much anything and turns it into a time.
I'm looking for something similar in Python?
As an example of why: I'm parsing syslogs which have the dumbest format ever (aka rfc3164) which omits a year and includes a space-padded day-of-month.
Currently in Python I'm doing this:
import datetime
d='Mar 5 09:10:11' # as an example
# first remove the space, if it exists
if d[4] == ' ':
d = d[0:4] + d[5:]
# append this year (I know, it could be last year around Dec/Jan!)
d = str(datetime.datetime.now().year) + ' ' + d
# now we can feed it strptime
date = datetime.strptime(d, "%Y %b %d %H:%M:%S")
This is really ugly.
Is there a better way?