This question already has answers here:
How to get day of the month?
                                
                                    (7个答案)
                                
                        
                2年前关闭。
            
        

如果今天是当前月份的第一天,我如何在Joda或Java中编写一个返回布尔值的方法?就像今天的日期是本月的第一天一样,它将返回true

可能是这样的:

public static boolean isFirstDayOfTheMonth( Date dateToday ){
boolean isFirstDay = false;
//code to check if dateToday is first day of the current month.
returns isFirstDay;
}


先感谢您!

最佳答案

LocalDate::getDayOfMonth

对于Java SE 8和更高版本,请调用LocalDate::getDayOfMonth

public static boolean isFirstDayOfTheMonth(LocalDate dateToday ){
  return dateToday.getDayOfMonth() == 1;
}

10-06 13:31