The previousOrSame(DayOfWeek) method of a TemporalAdjusters class is used to return a previous or same day-of-week TemporalAdjuster object which can be used to get a new Date object which is the previous or same date with the same matching day-of-week as passed as a parameter from any Date object on which this TempotralAdjuster is applied.
public static TemporalAdjuster previousOrSame(DayOfWeek dayOfWeek)
Parameters: This method accepts dayOfWeek which can be used to get a new Date object which is the previous or same date with the same matching day-of-week as passed. It should not be null.
Return value: This method return a previous or same day-of-week TemporalAdjuster object.
Below programs illustrate the TemporalAdjusters.previousOrSame() method:
Previous or same date having FRIDAY for localdate 2020-10-30 is: 2020-10-30
Previous or same date having THURSDAY for localdate 2018-02-23 is: 2018-02-22
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.