python 获取当天和前几天时间数据

python 获取当天和前几天时间数据

import datetime
from datetime import datetime, date, timedelta


def dayDateRange():
    dates = []
    for i in range(2, -1, -1):
        yesterday = (date.today() + timedelta(days=-i)).strftime("%Y-%m-%d")  # 昨天日期
        dates.append(yesterday)
    return dates


if __name__ == '__main__':
    print(dayDateRange())
    pass

  

posted @ 2019-11-21 11:20  小学弟-  阅读(1608)  评论(0编辑  收藏  举报