Java.Java8.How to get next Tuesday using Date Time API?

✅ Use TemporalAdjusters.next(DayOfWeek.TUESDAY)

import java.time.LocalDate;
import java.time.DayOfWeek;
import java.time.temporal.TemporalAdjusters;

public class NextTuesdayExample {
    public static void main(String[] args) {
        LocalDate today = LocalDate.now();

        LocalDate nextTuesday = today.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));

        System.out.println("Today:        " + today);
        System.out.println("Next Tuesday: " + nextTuesday);
    }
}

🔹 Output Example:

Today:        2025-04-15
Next Tuesday: 2025-04-22

🔸 Bonus: If Today Is Tuesday and You Want the Next One

  • TemporalAdjusters.next()always moves to the next one, even if today is Tuesday
  • TemporalAdjusters.nextOrSame() → includes today if it’s already Tuesday
LocalDate nextOrSameTuesday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.TUESDAY));
This entry was posted in Без рубрики. Bookmark the permalink.