python判断是否是周末

import datetime

def is_weekend(date_param: str):
    """
    是否是周末
    @:param: date_param 日期。如 2020-01-01
    """
    # 标准日1
    sd1 = '2022-11-19'
    # 标准日2
    sd2 = '2022-11-20'
    # 日期格式
    format = '%Y-%m-%d'
    # 时间间隔。七整天
    interval = 7
    sd1 = datetime.datetime.strptime(sd1, format)
    sd2 = datetime.datetime.strptime(sd2, format)
    the_date = datetime.datetime.strptime(date_param, format)
    compute_interval1 = abs((the_date-sd1).days / interval)
    compute_interval2 = abs((the_date-sd2).days / interval)
    return compute_interval1 == int(compute_interval1) or compute_interval2 == int(compute_interval2)


if __name__ == '__main__':
    print(is_weekend('2022-03-27'))

你可能感兴趣的:(实践,java)