📜  python 从日期中减去月份 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:27.087000             🧑  作者: Mango

代码示例1
# 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