How to calculate remaining days of the month? [duplicate]

In Java there’s been for a while Java Time API, which allows to get the number of days in the given month and calculate the difference using java.time.temporal.ChronoUnit.DAYS:

LocalDate today = LocalDate.now();
LocalDate endOfMonth = today.withDayOfMonth(today.lengthOfMonth());
long daysBetween = DAYS.between(today, endOfMonth);

Leave a Comment