Parsing non-zero padded timestamps in Python

后端 未结 5 1817
误落风尘
误落风尘 2020-12-05 01:39

I want to get datetimes from timestamps like the following :3/1/2014 9:55 with datetime.strptime, or something equivalent.

The month, day o

5条回答
  •  误落风尘
    2020-12-05 02:05

    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")
    

提交回复
热议问题