I have the following code (based on http://strftime.org/):
try:
datetime.datetime.strptime("Apr 14, 2016 9", '%b %d, %Y %-I')
print "matched date format"
except ValueError:
print "did NOT match date format"
The above prints:
$ python parse_log.py
did NOT match date format
However bash recognizes this date format:
$ date '+%b %d, %Y %-I'
Apr 14, 2016 1
What am I missing?
It seems that the %-I is the problem, since Python matches date without the %-I section:
try:
datetime.datetime.strptime("Apr 14, 2016 ", '%b %d, %Y ')
print "matched date format"
except ValueError:
print "did NOT match date format"
output:
$ python parse_log.py
matched date format
I'm on python 2.6.6.
The actual pattern I need to match uses 12 hour clock and is:
datetime.datetime.strptime("Apr 14, 2016 9:59:54", '%b %d, %Y %-I:%M:%S')