无法转换“00:30 AM"到 24 小时通过 strptime python [英] Not able to convert "00:30 AM" to 24 hours by strptime python
问题描述
我正在尝试将00:30 AM"转换为 24 小时时间,但它给出了 ValueError: time data '00:30 AM' does not match format '%I:%M %p'
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'
使用的代码是:
datetime.datetime.strptime('00:30 AM','%I:%M %p')
有人可以帮我解决这个错误吗?
Can somebody please help me solving this error?
推荐答案
%I
格式需要 1 和 12 之间的数字,而不是 0 和 12.12 小时制总是使用 12
表示午夜或中午.
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.
来自 strftime()
文档:
%I
小时(12 小时制)作为用零填充的十进制数.
01, 02, ..., 12
%I
Hour (12-hour clock) as a zero-padded decimal number.
01, 02, ..., 12
将 00
替换为 12
或使用不同的解析方法.
Either replace the 00
with 12
or use a different method of parsing.
这篇关于无法转换“00:30 AM"到 24 小时通过 strptime python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!