[英]ValueError: time data '24:00' does not match format '%H:%M'
I'm having serious trouble converting 24 hour time to 12 hour. 我在24小时转换为12小时时遇到了严重问题。
def standard_time(t):
t = datetime.strptime(t, "%H:%M")
return t
When fed in '24:00'
we get 当我们在'24:00'
喂食时,我们得到了
ValueError: time data '24:00' does not match format '%H:%M'
I also attempt converting using %I (12 hour) instead of %H, but get an error whenever hours go over 12: 我也尝试使用%I(12小时)而不是%H进行转换,但每当小时数超过12时都会收到错误:
def standard_time(t):
t = datetime.strptime(t, "%I:%M")
return t
Sort of stuck... 陷入困境......
ValueError: time data '13:30' does not match format '%I:%M'
Does python have a simple 24 hour to 12 hour converter? python有一个简单的24小时到12小时的转换器吗? Ideally 23:00 should put out 11:00 PM and 24:00 should not throw an error! 理想情况下23:00应该放出晚上11:00和24:00不应该抛出错误!
You have to give 00:00
for 24:00
. 你必须在24:00
给00:00
。 Last count in 24 hour format is 23:59
after that next value will be 00:00
. 24小时格式的最后计数是23:59
之后的下一个值将是00:00
。
Like if you have 23:59
, and add one more minutes in that 就像你有23:59
,然后又增加一分钟
>>> a = datetime(1900, 1, 1, 23, 59)
>>> from datetime import timedelta
>>> a + timedelta(minutes=1)
datetime.datetime(1900, 1, 2, 0, 0)
You will get next date with 00:00
您将在00:00
获得下一个约会
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.