LocalDateTime获取上一个时间点和下一个时间点
//获取下一个时间点,如现在为15:30,上一个整点时间点为,16:00
LocalDateTime.now().withMinute(0).withSecond(0).withNano(0).plusHours(1);
//获取上一个时间点,如现在为15:30,上一个整点时间点为,15:00
LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
//LocalDateTime转Date
public static Date toDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
//Date转LocalDateTime
public static LocalDateTime toLocalDateTime(Date dateTime) {
return dateTime.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
}