zl程序教程

您现在的位置是:首页 >  其他

当前栏目

获取本周或更多的日期

日期 获取 本周
2023-09-14 09:00:33 时间

获取本周或更多的日期

import time


def get_this_week_all_date(default_days=7):
    # 获取本周的7个日期
    # 1、获取当前时间戳
    st_now = int(time.time())

    # 2、获取当前星期几 %w 星期(0-6),星期天为星期的开始
    date_format = "%w"
    week_day_num = timestamp2date(st_now, date_format)

    if int(week_day_num) == 0:  # 修正星期天
        week_day_num = 7
# 3、获取本周星期一时间戳 st_week1 = st_now - (int(week_day_num) - 1) * (24 * 3600) # 4、获取本周星期一日期 # w1_num = timestamp2date(st_week1, "%w") w1_date = timestamp2date(st_week1, "%Y%m%d") # 5、获取本周7个日期,或者更多日期 w1_date_int = int(w1_date) thisweek_all_date_or_more = [str(w_date_int) for w_date_int in range(w1_date_int, w1_date_int + default_days)] return thisweek_all_date_or_more if __name__ == '__main__': this_week_all_date = get_this_week_all_date(10) print(this_week_all_date)

  

输出: