獲取當前日期前一天日期:
from datetime import datetime, date, timedelta yesterday = date.today() + timedelta(days = -1) # 昨天日期
返回結果:
datetime.date(2018, 7, 16)
可以選擇格式化輸出:
yesterday = (date.today() + timedelta(days = -1)).strftime("%Y-%m-%d") # 昨天日期
返回結果:
'2018-07-16'
