last day of month calculation
java.time.temporal.TemporalAdjusters.lastDayOfMonth()
Using the java.time
library built into Java 8, you can use the TemporalAdjuster
interface. We find an implementation ready for use in the TemporalAdjusters
utility class: lastDayOfMonth
.
import java.time.LocalDate;import java.time.temporal.TemporalAdjusters;LocalDate now = LocalDate.now(); //2015-11-23LocalDate lastDay = now.with(TemporalAdjusters.lastDayOfMonth()); //2015-11-30
If you need to add time information, you may use any available LocalDate
to LocalDateTime
conversion like
lastDay.atStartOfDay(); //2015-11-30T00:00