Jpp已经添加了解决方案,但只是添加了一个更具可读性的格式化字符串-
请访问此真棒网站。
import calendardef last_thurs_date(date): year, month = date.year, date.month cal = calendar.monthcalendar(year, month) # the last (4th week -> row) thursday (4th day -> column) of the calendar # except when 0, then take the 3rd week (February exception) last_thurs_date = cal[4][4] if cal[4][4] > 0 else cal[3][4] return f'{year}-{month:02d}-{last_thurs_date}'还增加了一些逻辑-例如,您得到的
2019-02-0是2月的整整4周。



