As a memorandum
It's easy to use LocalDate.
//today
LocalDate now = LocalDate.now(); // 2020-06-23: Tuesday
//this Friday
LocalDate thisFriday = now.with(DayOfWeek.FRIDAY); // 2020-06-26
//Last wednesday
LocalDate lastWednesDay = now.minusWeeks(1).with(DayOfWeek.WEDNESDAY); // 2020-06-17
//Next thursday
LocalDate nextThursDay = now.plusWeeks(1).with(DayOfWeek.THURSDAY); // 2020-07-02
//Bonus: Convert to LocalDateTime
LocalDateTime from = lastWednesDay.atTime(00, 00, 00); // 2020-06-17 00:00:00
Date and Time API Tips for Japanese (ja) [Java] Get the dates of the past Monday and Sunday in order @ kazokclily
Recommended Posts