I want to groupingBy a Collection based on the LocalDateTime, but I only want to get the Hour, not the minutes, seconds...
.collect(Collectors.groupingBy(cp -> getUpdateLocalDate())
public LocalDate getUpdateLocalDate() {
return getUpdateDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
but I need also the Date, something like: 2018-10-12T09:00:00
, not only the hour
note that LocalDate
doesn't have a time-zone. instead, return a LocalDateTime from the method getUpdateLocalDate
(might be worth renaming also) then truncate the LocalDateTime instance.
.collect(Collectors.groupingBy(cp -> cp.getUpdateLocalDateTime().truncatedTo(ChronoUnit.HOURS));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With