我这个人不好罗里吧嗦的直接上代码
def get_month_date(date):
week_date = date.split("-")
date_obj = datetime(int(week_date[0]), int(week_date[1]), int(week_date[2]))
this_month_start = datetime(date_obj.year, date_obj.month, 1).strftime("%Y-%m-%d")
month_all_days = calendar.monthrange(date_obj.year, date_obj.month)
this_month_end = (datetime(date_obj.year, date_obj.month, month_all_days[1]) + timedelta(hours=23, minutes=59, seconds=59)).strftime("%Y-%m-%d")
return this_month_start, this_month_end
# 测试
get_month_date("2022-12-10")