这个要怎么做,求大神解答。
2 回答
已采纳
car
TA贡献184条经验 获得超33个赞
public class TestMain { public static void main(String[] args) { int n = 1;//输入的日期数字1-7 LocalDate date = LocalDate.now(); int year = date.getYear(); LocalDate startDate = LocalDate.parse(year+"-01-01"); LocalDate endDate = LocalDate.parse(year+"-12-31"); int startDay = startDate.getDayOfYear(); int endDay = endDate.getDayOfYear(); DayOfWeek dayOfWeek = null; while (startDay <= endDay) { dayOfWeek = startDate.getDayOfWeek(); int value = dayOfWeek.getValue(); if (value == n) { System.out.println(startDate); } startDate = startDate.plusDays(1); startDay++; } } }
添加回答
举报
0/150
提交
取消