public String getLastDayOfMonth(int year,int month) {
Calendar cal = Calendar.getInstance();
//设置年份
cal.set(Calendar.YEAR,year);
//设置月份
cal.set(Calendar.MONTH, month-1);
//获取某月最大天数
int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
//设置日历中月份的最大天数
cal.set(Calendar.DAY_OF_MONTH, lastDay);
//格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String lastDayOfMonth = sdf.format(cal.getTime());
return lastDayOfMonth;
}
java得到某一年某一月的最后一天
最新推荐文章于 2024-08-16 10:31:27 发布