python循环日期

2020-06-03  本文已影响0人  戒灵
from datetime import datetime, date, timedelta

begin_date=date.today()+timedelta(days=-2) #美国当前日期6.1
begin_str=str(begin_date)
begin14_date = date.today()-timedelta(days=16)#14天前日期
begin14_str = str(begin14_date)
while begin_str>begin14_str:
    begin_date=begin_date+timedelta(days=-1)
    begin_str = str(begin_date)
    print(begin_str)

运行结果
![[47F69VS~OP6E6FWLX1QP5.png

上一篇下一篇

猜你喜欢

热点阅读