Not able to convert “00:30 AM” to 24 hours by strptime python

我是研究僧i 提交于 2019-12-08 10:21:46

问题


I am trying to convert "00:30 AM" to 24 hours time but it gives ValueError: time data '00:30 AM' does not match format '%I:%M %p'

The code used is:

datetime.datetime.strptime('00:30 AM','%I:%M %p')

Can somebody please help me solving this error?


回答1:


The %I format expects a number between one and twelve, not zero and twelve. A 12 hour clock always uses 12 for midnight or noon.

From the strftime() documentation:

%I
Hour (12-hour clock) as a zero-padded decimal number.
01, 02, ..., 12

Either replace the 00 with 12 or use a different method of parsing.



来源:https://stackoverflow.com/questions/31582467/not-able-to-convert-0030-am-to-24-hours-by-strptime-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!