Find the date for the first Monday after a given a date

后端 未结 11 1662
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 15:47

Given a particular date, say 2011-07-02, how can I find the date of the next Monday (or any weekday day for that matter) after that date?

11条回答
  •  孤城傲影
    2020-11-27 16:36

    import datetime
    
    d = datetime.date(2011, 7, 2)
    while d.weekday() != 0:
        d += datetime.timedelta(1)
    

提交回复
热议问题