python如何取前一天和上一年

import time, os
import datetime
def getYesterday():
    today = datetime.date.today()
    oneday = datetime.timedelta(days=1)
    yesterday = today - oneday
    return yesterday
def getCurrentYear():
    now = datetime.datetime.now()
    last_year = int(now.year) - 1
    return last_year

print(getYesterday())
print(getCurrentYear())

你可能感兴趣的:(python)