def deadlines(t):
'''shows pretty time to deadlines'''
fmt = '%a %d %m %Y %I:%M %p %Z'
dt = datetime.strptime( t , fmt )
print 'dt ', repr(dt)
first = 'Sun 11 May 2014 05:00 PM PDT'
deadlines(first)
ValueError: time data 'Sun 11 May 2014 02:00 PM PDT' does not match format ' %a %d %m %Y %I:%M %p %Z '
Whats wrong with this?
%m
matches months represent as a two-digit decimal (in[01, 12]
). Use%b
for abbreviated month names, or%B
for full month names instead:A table showing the date format directives and their meanings can be found here.
If you're having trouble parsing
PDT
using%Z
:Per the time.strptime docs:
So, if parsing the date string without PDT works:
but
raises a ValueError, then you may need strip off the timezone name (they are, in general, ambiguous anyway):
or use dateutil: