各月の第三日曜日は?
今年の各月の第三日曜日がいつなのかを見てみる。
import static java.time.DayOfWeek.SUNDAY; import java.time.LocalDate; import static java.time.temporal.TemporalAdjusters.dayOfWeekInMonth; public class ThirdSundays { public static void main(String[] args) { final LocalDate START = LocalDate.of(2016, 1, 1); final LocalDate END = LocalDate.of(2017, 1, 1); for (LocalDate d = START; d.isBefore(END); d = d.plusMonths(1)) { System.out.println( d.with(dayOfWeekInMonth(3, SUNDAY)) ); } } }
$ java ThirdSundays 2016-01-17 2016-02-21 2016-03-20 2016-04-17 2016-05-15 2016-06-19 2016-07-17 2016-08-21 2016-09-18 2016-10-16 2016-11-20 2016-12-18