import datetime
def last_day_of_month(any_day):
"""
获取获得一个月中的最后一天
:param any_day: 任意日期
:return: string
"""
next_month = any_day.replace(day=28) + datetime.timedelta(days=4) # this will never fail
return next_month - datetime.timedelta(days=next_month.day)
year = 2022 # 年
month = 3 # 月
day = 11 # 日
res = last_day_of_month(datetime.date(year, month, day))
print(res)
today = datetime.date.today()
res = last_day_of_month(today)
print(res)
2022-03-31
2022-09-30