localDateTime minusHours
时间: 2024-05-02 21:18:17 浏览: 158
Spring中使用LocalDateTime、LocalDate等参数作为入参
To subtract hours from a LocalDateTime object in Java, you can use the `minusHours()` method.
Here's an example:
```
LocalDateTime dateTime = LocalDateTime.now(); // current date and time
LocalDateTime minusTwoHours = dateTime.minusHours(2); // subtract 2 hours
```
In this example, we create a LocalDateTime object for the current date and time using the `now()` method. Then, we use the `minusHours()` method to subtract 2 hours from the LocalDateTime object, and assign the result to a new LocalDateTime variable called `minusTwoHours`.
You can replace the `2` in the `minusHours()` method with any number of hours you want to subtract.
阅读全文