安装
pip install python-dateutil
代码示例
from datetime import datetime, date from dateutil.relativedelta import relativedelta now = datetime.now() print(now) print(now - relativedelta(months=3)) """ 2019-01-09 18:13:28.791192 2018-10-09 18:13:28.791192 """ today = date.today() print(today) print(today - relativedelta(months=3)) """ 2019-01-09 2018-10-09 """