java 获取本周二到下周一日期 与获取明天日期与获取上周二到本周一日期
时间: 2024-03-26 12:35:00 浏览: 70
java 查询本周一和本周日的日期
5星 · 资源好评率100%
获取本周二到下周一日期的Java代码:
```java
import java.time.DayOfWeek;
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate date = LocalDate.now();
LocalDate nextTuesday = date.with(DayOfWeek.TUESDAY);
LocalDate nextMonday = date.with(DayOfWeek.MONDAY).plusWeeks(1);
System.out.println("本周二到下周一日期:");
System.out.println("周二:" + nextTuesday);
System.out.println("周三:" + nextTuesday.plusDays(1));
System.out.println("周四:" + nextTuesday.plusDays(2));
System.out.println("周五:" + nextTuesday.plusDays(3));
System.out.println("周六:" + nextTuesday.plusDays(4));
System.out.println("周日:" + nextTuesday.plusDays(5));
System.out.println("周一:" + nextMonday);
}
}
```
获取明天日期的Java代码:
```java
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate tomorrow = LocalDate.now().plusDays(1);
System.out.println("明天日期:" + tomorrow);
}
}
```
获取上周二到本周一日期的Java代码:
```java
import java.time.DayOfWeek;
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate date = LocalDate.now();
LocalDate lastTuesday = date.with(DayOfWeek.TUESDAY).minusWeeks(1);
LocalDate lastMonday = date.with(DayOfWeek.MONDAY).minusWeeks(1);
System.out.println("上周二到本周一日期:");
System.out.println("上周二:" + lastTuesday);
System.out.println("上周三:" + lastTuesday.plusDays(1));
System.out.println("上周四:" + lastTuesday.plusDays(2));
System.out.println("上周五:" + lastTuesday.plusDays(3));
System.out.println("上周六:" + lastTuesday.plusDays(4));
System.out.println("上周日:" + lastTuesday.plusDays(5));
System.out.println("本周一:" + lastMonday);
}
}
```
阅读全文