首先,设置一个日期-
LocalDate date = LocalDate.of(2019, Month.APRIL, 1);
现在,使用firstInMonth()
方法获得第一个星期五。在这里,您必须将DayOfWeek设置为星期五,因为我们想要一个月中的第一个星期五-
LocalDate firstFriday = date.with(TemporalAdjusters.firstInMonth(DayOfWeek.FRIDAY));
import java.time.DayOfWeek; import java.time.LocalDate; import java.time.Month; import java.time.temporal.TemporalAdjusters; public class Demo { public static void main(String[] args) { LocalDate date = LocalDate.of(2019, Month.APRIL, 1); System.out.println("Current date = "+date); LocalDate firstFriday = date.with(TemporalAdjusters.firstInMonth(DayOfWeek.FRIDAY)); System.out.println("First Friday date = "+firstFriday); } }
输出结果
Current date = 2019-04-01 First Friday date = 2019-04-05