Foggy day

Android(JAVA) - How to get number of days in this month, YearMonth 본문

Android

Android(JAVA) - How to get number of days in this month, YearMonth

jinhan38 2021. 1. 7. 13:27

It is the code about How to get number of days in this month as using YearMonth Class.

 

 

If you want to know number of days in this month, It is that.

 

 public static int getDayCountOfThisMonth() {
        Date date = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        String time = sf.format(date);
        YearMonth dayCount = YearMonth.from(LocalDate.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd")));

        return dayCount.lengthOfMonth();
    }
}