datetime模块
获取当前日期
import datetime
today = datetime.date.today()
获取昨天日期
import datetime
# 获取昨天日期
def getYesterday():
today=datetime.date.today()
oneday=datetime.timedelta(days=1)
yesterday=today-oneday
return yesterday
# 优化版
def get_yesterday():
yesterday = datetime.date.today() + datetime.timedelta(-1)
return yesterday
yesterday = get_yesterday()