- Instant help with your Java coding problems

Get the first day of the week in Java

Question:
How to get the first day of the week in Java?
Answer:
LocalDate now = LocalDate.now();

LocalDate firstDayOfWeek = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
Description:

To get the first day of a week based on the current date, use the previousOrSame() adjuster.


It returns the previous-or-same day-of-week adjuster, which adjusts the date to the first occurrence of the specified day-of-week before the date being adjusted unless it is already on that day in which case the same object is returned.

 

Share "How to get the first day of the week in Java?"