What comparator should I use to sort a TreeMap<Date, Long> if I want its keys to be "the same" if they hold the same DAY.
What I'm trying to say is that I want "15.09.2022 at 12:00" and "15.09.2022 at 12:01" to be the same.
I came up with an idea
Map<Date, Long> map = new TreeMap<>((date1, date2) -> {
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
return fmt.format(date1).compareTo(fmt.format(date2));
});
But it isn't quite the best practice to cast Dates to Strings every time. Is there a more elegant way to do it?