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)
标签:relativedelta,Python,datetime,获取,日期,print,d2,d3,d1 From: https://www.cnblogs.com/lucktomato/p/16708979.html