- Instant help with your Java coding problems

Get the last day of a month in Java

Question:
How to get the last day of a month in Java?
Answer:
LocalDate now = LocalDate.now();

LocalDate lastDay = now.with(TemporalAdjusters.lastDayOfMonth());
Description:

The TemporalAdjusters contains common and useful adjusters. Adjusters are a key tool for modifying temporal objects. They exist to externalize the process of adjustment, permitting different approaches, as per the strategy design pattern.

The lastDayOfMonth() method returns a new date set to the last day of the current month. Use it as a parameter for the with() method on your LocalDate object. The with() method returns an adjusted copy of this date.

Share "How to get the last day of a month in Java?"