python3-cookbook icon indicating copy to clipboard operation
python3-cookbook copied to clipboard

3.14 计算当前月份日期范围 例子不符合预期

Open fengtangzheng opened this issue 4 years ago • 1 comments

def get_month_range(start_date=None):
    if start_date is None:
        start_date = date.today().replace(day=1)
    _, days_in_month = calendar.monthrange(start_date.year, start_date.month)
    end_date = start_date + timedelta(days=days_in_month)
    return (start_date, end_date)
def get_month_range(start_date=None):
    if start_date is None:
        start_date = date.today()
    start_date = start_date.replace(day=1)
    _, days_in_month = calendar.monthrange(start_date.year, start_date.month)
    end_date = start_date + timedelta(days=days_in_month)
    return (start_date, end_date)

fengtangzheng avatar Feb 19 '21 11:02 fengtangzheng

可以说一下不符合预期的结果吗。我这里试了一下没什么问题,Python 3.8.6 (32-bit)

zlu27 avatar Feb 20 '21 05:02 zlu27