• Post author:
  • Post category:python
  • Post comments:0评论
Like
Like Love Haha Wow Sad Angry

脚本内容:

from datetime import datetime
from datetime import timedelta

def get_weekday(datestring):
    week_day_dict = {
        1: '星期一',
        2: '星期二',
        3: '星期三',
        4: '星期四',
        5: '星期五',
        6: '星期六',
        7: '星期天',
    }
    week_day = datetime.strptime(datestring, "%Y-%m-%d").isoweekday()   # 返回数字1-7代表周一到周日
    return week_day_dict[week_day]

for i in range(0, 7):
    date = (datetime.now() + timedelta(days=i)).strftime("%Y-%m-%d")
    date1 = (datetime.now() + timedelta(days=i)).strftime("%m-%d")
    print(f'{date1}({get_weekday(date)})')

执行结果:

12-27(星期一)
12-28(星期二)
12-29(星期三)
12-30(星期四)
12-31(星期五)
01-01(星期六)
01-02(星期天)
Like
Like Love Haha Wow Sad Angry

发表评论