问题
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