Java/Python,某月最后一天是几号?

Java 版

Calendar 中设置好年、月(默认为当月),调用如下方法:

Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);  // 返回 int

Python 版

使用 calendar 模块中的 monthrange 方法

monthrange(year, month)
Returns weekday of first day of the month and number of days in month, for the specified year and month.

In [1]: import calendar

In [2]: calendar.monthrange(2017, 11)[1]
Out[2]: 30

站长数十年成长感悟,输入暗号查看

桩白墨公众号上还能加入书舟书友群、美团外卖红包群,免费领取站桩和原创 chatgpt 教程哦
暗号:
请关注本站微信公众号,回复“暗号”,即可获取。在微信里搜索“桩白墨”或者“baimoz”或者微信扫描右侧二维码都可以关注站长微信公众号。