简体   繁体   English

ValueError:时间数据'24:00'与格式'%H:%M'不匹配

[英]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:0000: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.

相关问题 ValueError:时间数据'10 / 11/2006 24:00'与格式'%d /%m /%Y%H:%M'不匹配 - ValueError: time data '10/11/2006 24:00' does not match format '%d/%m/%Y %H:%M' ValueError: 时间数据 '2013/05/24 07:00:00' 与格式 '%Y-%m-%d %H:%M:%S' 不匹配 - ValueError: time data '2013/05/24 07:00:00' does not match format '%Y-%m-%d %H:%M:%S' ValueError:时间数据“ 1:00:00”与格式“%H:%M:%S”不匹配 - ValueError: time data ' 1:00:00' does not match format '%H:%M:%S' ValueError:时间数据'1/1/2016 00:09:55'与格式'%m /%d /%y%H:%M:%S'不匹配 - ValueError: time data '1/1/2016 00:09:55' does not match format '%m/%d/%y %H:%M:%S' ValueError:时间数据'2012-07-19 08:24:00'与格式'%Y-%m-%d H:M:S'不匹配 - ValueError: time data '2012-07-19 08:24:00' does not match format '%Y-%m-%d H:M:S' ValueError: 时间数据“00:01:29:06”与格式“%d:%H:%M:%S”不匹配 - ValueError: time data '00:01:29:06' does not match format '%d:%H:%M:%S' ValueError:时间数据“在00天23:07:56”与格式“在%d天%H:%M:%S”不匹配 - ValueError: time data 'In 00 days 23:07:56' does not match format 'In %d days %H:%M:%S' ValueError:时间数据'0000-00-00 00:00:00'与格式'%Y-%m-%d%H:%M:%S'不匹配 - ValueError: time data '0000-00-00 00:00:00' does not match format '%Y-%m-%d %H:%M:%S' Python 时间数据 '2008-01-24T00:00:00:000' 与格式 '%Y-%m-%d %H:%M :%S:%f' 不匹配 - Python time data '2008-01-24T00:00:00:000' does not match format '%Y-%m-%d %H:%M :%S:%f' 时间数据“0:02:00”与格式“%H %M %S”不匹配 - time data '0:02:00' does not match format '%H %M %S'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM