Python 获取当前周的 周一及周日 时间

2019-03-19  本文已影响0人  de650ed0ad7e

import datetime

def get_current_week():
monday, sunday = datetime.date.today(), datetime.date.today()
one_day = datetime.timedelta(days=1)
while monday.weekday() != 0:
monday -= one_day
while sunday.weekday() != 6:
sunday += one_day
# 返回当前的星期一和星期天的日期
return monday, sunday

print(get_current_week())

上一篇下一篇

猜你喜欢

热点阅读