【发布时间】:2021-08-09 18:12:01
【问题描述】:
我尝试将像 1:34.21 这样的严格时间转换为时间。
我使用这个datetime.strptime('1:34.21', '%-H:%M.%S').time() 进行转换,但我提出了这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_strptime.py", line 341, in _strptime
raise ValueError("'%s' is a bad directive in format '%s'" %
ValueError: '-' is a bad directive in format '%-H:%M.%S'
【问题讨论】:
标签: python python-3.x datetime strptime