java 获取本周二到下周一日期 与获取明天日期与获取上周二到本周一日期
时间: 2024-03-26 22:35:00 浏览: 64
java 获取当前日期时间和本周的星期一的日期时间.docx
获取本周二到下周一日期的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);
}
}
```
阅读全文