"如何获取下个月的 1 号和最后一天,"
如何获取下个月的 1 号和最后一天,
借鉴一下
import datetime import calendar def get_date_of_next_month(): """ 获取下月开始结束日期 :return: str,date tuple """ today = datetime.date.today() year = today.year month = today.month if month == 12: year += 1 month = 1 else: month += 1 begin_of_next_month = datetime.date(year, month, 1).strftime('%Y-%m-%d') _, day = calendar.monthrange(year, month) end_of_next_month = datetime.date(year, month, day).strftime('%Y-%m-%d') return begin_of_next_month, end_of_next_month ```
借鉴一下