Question Details

No question body available.

Tags

java datetime calendar java.util.calendar

Answers (1)

Accepted Answer Available
Accepted Answer
September 2, 2025 Score: 6 Rep: 349,424 Quality: Expert Completeness: 80%

tl;dr

Use only java.time classes for date-time work. Never use Calendar.

LocalDate .of( 2025 , Month.AUGUST , 16 ) .with( TemporalAdjusters.previousOrSame ( DayOfWeek.MONDAY ) )

Avoid legacy date-time classes

Never use the terribly flawed legacy date time classes such as Date, Calendar, and SimpleDateFormat.

Use only the modern java.time classes.

java.time

Represent a date with java.time.LocalDate.

LocalDate ld = LocalDate.of( 2025 , Month.AUGUST , 16 ) ;

Use a TemporalAdjuster (class name is singular) to get the previous Monday, or get the same date if it is a Monday. The utility class TemporalAdjusters (class name is plural) provides the adjuster you need.

TemporalAdjuster adjuster = TemporalAdjusters.previousOrSame ( DayOfWeek.MONDAY ) ;

Apply the adjuster to produce a LocalDate object.

LocalDate previousOrSameMonday = ld.with( adjuster ) ;