ValueError: time data 'In 00 days 23:07:56' does not match format 'In %d days %H:%M:%S'

删除回忆录丶 提交于 2021-01-29 05:04:53

问题


I am trying to parse my date string with time library. But i have an error in parsing.

# Example is 'In 0 days 23:07:56'
client['license_time_start'] = time.strptime('In 0 days 23:07:56', 'In %d days %H:%M:%S')

ValueError: time data 'In 00 days 23:07:56' does not match format 'In %d days %H:%M:%S'


回答1:


The error is because date can't be 0. It has to be an positive integer.

Therefore, this produces an error:-

time.strptime('In 0 days 23:07:56', 'In %d days %H:%M:%S')
# ValueError: time data 'In 0 days 23:07:56' does not match format 'In %d days %H:%M:%S'

This doesn't:-

time.strptime('In 01 days 23:07:56', 'In %d days %H:%M:%S')
# time.struct_time(tm_year=1900, tm_mon=1, tm_mday=1, tm_hour=23, tm_min=7, tm_sec=56, tm_wday=0, tm_yday=1, tm_isdst=-1)


来源:https://stackoverflow.com/questions/56993382/valueerror-time-data-in-00-days-230756-does-not-match-format-in-d-days-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!