我的日期时间转换有效,现在我没有做任何更改时就收到此错误。
time data '2019-04-14_27-35-34-859' does not match format '%Y-%m-%d_%H-%M-%S-%f'
def get_milliseconds(time_stamp):
utc_time = datetime.strptime(time_stamp,
'%Y-%m-%d_%H-%M-%S-%f')
milliseconds = (utc_time - datetime(1970, 1, 1)) // timedelta(milliseconds=1)
print("milliseconds = " + str(milliseconds))
return milliseconds
答案 0 :(得分:1)
您%H
的值无效-小时只能是00-23,而不是24+(这很合理,您一天没有27小时)。
不幸的是,错误消息实际上并没有帮助,但是如果您从字符串中排除分钟/秒/毫秒,则会出现一条更有用的消息:
>>> s = '2019-04-14_27'
>>> datetime.datetime.strptime(s, '%Y-%m-%d_%H')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_strptime.py", line 362, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: 7