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.
Reference:
Java lastDayOfMonth reference
Share "How to get the last day of a month in Java?"
Related snippets:
- Get the last Friday of a month in Java
- Get the first Monday of a month in Java
- Get the first day of the week in Java
- Get the first day of the current month in Java
- Get the last day of a month in Java
- Get the number of days between two dates in Java
- Get yesterday's date in Java
- Get tomorrow's date in Java
- Get actual date in Java
Tags:
last day of month, the last day of current month, java Technical term:
Get the last day of a month in Java