Date out of range
At that time, I used the datetime module to generate time format data, and I mistakenly transmitted the result caused by wrong parameters. So, a good check of the data can solve the problem
As follows:
# Convert string type data to time structured data
# Originally, I wanted to write the following code
import datetime
date_init = '2019-05-10 00:00:00'
date_end = datetime.datetime(int(date_init.split('-')[0]), int(date_init.split('-')[1]),int(date_init.split('-')[2].split(' ')[0].lstrip('0')), int(date_init.split('-')[2].split(' ')[1].split(':')[0]), int(date_init.split('-')[2].split(' ')[1].split(':')[1]), int(date_init.split('-')[2].split(' ')[1].split(':')[2]))
print date_end,type(date_end)
#Hand shaking is wrong, as follows:
import datetime
date_init = '2019-05-10 00:00:00'
date_end = datetime.datetime(int(date_init.split('-')[0]), int(date_init.split('-')[1]),int(date_init.split('-')[2].split(' ')[0].lstrip('1')), int(date_init.split('-')[2].split(' ')[1].split(':')[0]), int(date_init.split('-')[2].split(' ')[1].split(':')[1]), int(date_init.split('-')[2].split(' ')[1].split(':')[2]))
print date_end,type(date_end)
Causes an error
In fact. Lstrip (‘0 ‘) can not be added. At that time, it was wrong to add parameters to datetime. Datetime (2019,05,05,00,00)
It’s over
Similar Posts:
- ValueError: day is out of range for month [How to Solve]
- TypeError: Object of type ‘datetime‘ is not JSON serializable [Solved]
- [Solved] java.lang.IllegalArgumentException: Cannot format given Object as a Date
- [Solved] Python Error: datetime.datetime is not JSON serializable
- [Solved] scheduler Error: maximum number of running instances reached
- Python: __ new__ Method and the processing of typeerror: object() takes no parameters
- Using Vue + Axios: axios.post error: request failed with status code 400 is one of the solutions
- TypeError: strptime() argument 1 must be str, not bytes
- [Solved] Typeerror: incorrect padding occurred in python3 Base64 decoding
- builtin_function_or_method’ object is not subscriptable [How to Solve]