Reputation: 5068
Pythonic way to get datetime from a string without leading zeroes?
e.g. no leading zero for Hour (typical case)
'Date: Jul 10, 2014 4:41:28 PM'
Upvotes: 0
Views: 938
Reputation: 174624
Without dateutil
:
>>> import datetime
>>> d = datetime.datetime.strptime(s, 'Date: %b %d, %Y %I:%M:%S %p')
>>> d.hour
16
>>> d
datetime.datetime(2014, 7, 10, 16, 41, 28)
Upvotes: 2