JAVA 判断一个日期是否是月末

1、月末+1=月初
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DATE, (calendar.get(Calendar.DATE) + 1));
if (calendar.get(Calendar.DAY_OF_MONTH) == 1) {
    return true;
}else{
    return false;
}

 

2、用getActualMaximum方法获取一个月的最大天数

Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int getDay = calendar.get(Calendar.DAY_OF_MONTH);
if(getDay == calendar.getActualMaximum(Calendar.DAY_OF_MONTH)){
    return true;
}else{
    return false;
}

 

 

 

你可能感兴趣的:(JAVA,月末,JAVA)