python 日期

# 现在
now = datetime.datetime.now()
# 365天前
before = now - datetime.timedelta(days=365)
# 格式化
before = before.strftime('%Y-%m-%d')

datime.date

d = datetime.date.today()
print(d)
d1 = d.replace(d.year-3)
print(d1)

你可能感兴趣的:(python 日期)