我是靠谱客的博主 秀丽超短裙,这篇文章主要介绍python计算得到当周周一的日期,现在分享给大家,希望可以做个参考。

主要依靠循环实现,判断weekday的时间为0(6),代表是周一(周日),将值返回;

代码思路如下所示:

def get_current_monday(current_date):
    today_time = datetime.datetime.strptime(current_date, '%Y%m%d')
    monday = today_time + datetime.timedelta(days=-7)
    one_day = datetime.timedelta(days=1)

    if monday.weekday() != 0:
        while monday.weekday() != 0:
            monday += one_day
        return str(monday)[0:10]
    else:
        return current_date[0:10]

最后

以上就是秀丽超短裙最近收集整理的关于python计算得到当周周一的日期的全部内容,更多相关python计算得到当周周一内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部