LocalDateTime.isAfter
时间: 2023-10-15 08:24:10 浏览: 159
LocalDateTime.isAfter是一个方法,用于比较当前的LocalDateTime对象与另一个指定的ChronoLocalDateTime对象。这个方法返回一个布尔值,表示当前的LocalDateTime对象是否在指定的ChronoLocalDateTime对象之后。
下面是一个示例代码,演示了如何使用LocalDateTime的isAfter方法来比较两个日期对象:
```
// 字符串的日期转为LocalDateTime格式的时间
LocalDateTime dateTime1 = LocalDateTime.parse("2022-11-12T00:00:00");
LocalDateTime dateTime2 = LocalDateTime.parse("2022-11-15T00:00:00");
if (dateTime1.isAfter(dateTime2)) {
System.out.println("dateTime1在dateTime2之后");
} else {
System.out.println("dateTime2在dateTime1之后");
}
```
根据上述代码,如果dateTime1在dateTime2之后,将输出"dateTime1在dateTime2之后",否则输出"dateTime2在dateTime1之后"。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [java 根据类名示例化类_Java LocalDateTime类| isAfter()方法与示例](https://blog.csdn.net/cumubi7552/article/details/107799334)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [LocalDate的isBefore和isAfter方法](https://blog.csdn.net/Clsrm/article/details/127860455)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文