📅  最后修改于: 2022-03-11 14:46:27.087000             🧑  作者: Mango
# To subtract or add months from date you can use the third party dateutil module.
import datetime
from dateutil.relativedelta import relativedelta
date = datetime.datetime.strptime("2021-12-31", "%Y-%m-%d")
date2 = date - relativedelta(months=1)
print date2