Python获取一个月后的日期

import datetime
from dateutil.relativedelta import relativedelta

t=datetime.datetime.now()

#当前日期
d = datetime.date.today()
print(d)

# 1天前
d1= d - relativedelta(days=1)
print(d1)

#  一个月前
d2=d - relativedelta(months=1)
print(d2)

# 1年前
d3=d - relativedelta(years=1)
print(d3)


# 1天后
d1=d - relativedelta(days=-1)
print(d1)

#  一个月后
d2=d - relativedelta(months=-1)
print(d2)

# 1年后
d3=d - relativedelta(years=-1)
print(d3)

如果报错需要先安装模块

pip install python-dateutil

  

  

posted @ 2022-09-19 20:35  lucky_tomato  阅读(640)  评论(0编辑  收藏  举报