LocalDateTime的minus方法
时间: 2023-12-06 22:37:16 浏览: 152
LocalDateTime的minus方法可以用于减去指定的时间量,例如减去一定的天数、小时数、分钟数等。下面是几个例子:
1. 减去一定的天数
```java
LocalDateTime localDateTime = LocalDateTime.of(2021, Month.JULY, 21, 14, 46, 56);
LocalDateTime result = localDateTime.minusDays(1);
System.out.println(result); // 输出:2021-07-20T14:46:56
```
2. 减去一定的小时数
```java
LocalDateTime localDateTime = LocalDateTime.of(2021, Month.JULY, 21, 14, 46, 56);
LocalDateTime result = localDateTime.minusHours(2);
System.out.println(result); // 输出:2021-07-21T12:46:56
```
3. 减去一定的分钟数
```java
LocalDateTime localDateTime = LocalDateTime.of(2021, Month.JULY, 21, 14, 46, 56);
LocalDateTime result = localDateTime.minusMinutes(30);
System.out.println(result); // 输出:2021-07-21T14:16:56
```
阅读全文