Detect months with 31 days

前端 未结 19 1625
南旧
南旧 2020-12-18 01:53

Is there an analogous form of the following code:

if(month == 4,6,9,11)
{
  do something;
}

Or must it be:

if(month == 4 ||         


        
19条回答
  •  暖寄归人
    2020-12-18 02:44

    No question about dates and Java would be complete without mentioning Joda Time.

    for(int i = DateTimeConstants.JANUARY; i <= DateTimeConstants.DECEMBER; i++) {
        LocalDate localDate = new LocalDate().withMonthOfYear(i);
        System.out.println("    " +localDate.toString("MMMM") + " - " + localDate.dayOfMonth().getMaximumValue());
    }
    

    January - 31
    February - 29
    March - 31
    April - 30
    May - 31
    June - 30
    July - 31
    August - 31
    September - 30
    October - 31
    November - 30
    December - 31

提交回复
热议问题