我正在使用Python將2天添加到Python中的特定日期。使用datetime.now()
,我可以添加2天。但不使用特定的日期。下面的代碼:將日期添加到特定日期時獲取值錯誤
import datetime
start_date = datetime.datetime.strptime('7/18/2016','%m/%d/%y')
date_to_start_predicting = start_date + datetime.timedelta(days=2) # Add 2 days
print(date_to_start_predicting)
,但我得到了以下錯誤:
Traceback (most recent call last):
File "C:/Users/Admin/Projects/DateAdd.py", line 3, in <module>
start_date = datetime.datetime.strptime('7/18/2016','%m/%d/%y')
File "C:\Python27\lib\_strptime.py", line 328, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: 16
可能是什麼原因?