Determine whether the specified date is the last day of the month

/** 
 * Determine whether the given date is the last day of the month 
 * @param date 
 * @return 
 */ 
public static boolean isLastDayOfMonth(Date date) { 
    //1. Create a calendar class 
    Calendar calendar = Calendar.getInstance(); 
    // 2. Set the current passed time, otherwise it is the current system date 
    calendar.setTime(date); 
    //3. The date of data is N, then N+1 [assuming that the current month has 30 days, 30+1=31, if the current month There are only 30 days, so the final result is 1, which is the 1st of the next month] 
    calendar.set(Calendar.DATE, (calendar.get(Calendar.DATE) + 1)); 
    //4. Determine whether it is the last day of the month [1==1 then it means that today is the last day of the month and returns true] 
    if (calendar.get(Calendar.DAY_OF_MONTH) == 1) { 
        return true; 
    }else{ 
        return false; 
    } 
}

Guess you like

Origin blog.csdn.net/snowing1997/article/details/127452123