# 如果是 0 则为今天, 1 为昨天, 以此类推...
def getdate(day): today = datetime.datetime.now() deviation = datetime.timedelta(days=-day) return (today + deviation).strftime('%Y-%m-%d %H:%S:%M') print(getdate(0))