Parsing non-zero padded timestamps in Python
Solution 1:
strptime
is able to parse non-padded values. The fact that they are noted as being padded in the formatting codes table applies to strftime
's output. So you can just use
datetime.strptime(datestr, "%m/%d/%Y %H:%M")
Solution 2:
strptime
isdo not require 0-padded values. See example below
datetime.strptime("3/1/2014 9:55", "%m/%d/%Y %H:%M")
output: datetime.datetime(2014, 3, 1, 9, 55)