在Python 3.7和2.7中,似乎strptime()
将解析一个将秒设置为60和61的时间:
>>> import time
>>> time.strptime('12:00:60', '%H:%M:%S')
time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=12, tm_min=0, tm_sec=60, tm_wday=0, tm_yday=1, tm_isdst=-1)
>>> time.strptime('12:00:61', '%H:%M:%S')
time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=12, tm_min=0, tm_sec=61, tm_wday=0, tm_yday=1, tm_isdst=-1)
>>> time.strptime('12:00:62', '%H:%M:%S')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\_strptime.py", line 571, in _strptime_time
tt = _strptime(data_string, format)[0]
File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\_strptime.py", line 362, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: 2 (but not 62 or higher):
这是什么原因?如果我将小时设置为25或将分钟设置为61,将不起作用,但是为什么秒显然可以通过?