P
P
piatachki2018-03-14 18:28:13
Java
piatachki, 2018-03-14 18:28:13

How to group times in Unix-time by day?

Hello.
There is a collection of entities (conditionally an event), which have a field This field stores time in UnixTime format. I need to count the number of events that happened in days. That is, ideally, you want to get at the output , where the key is the day (just a day, without time), and the value is the number of events. And something I have an algorithmic plug. I feel that I need to write a function for , which takes UnixTime as input, and gives a date without time as output. But at the same time, I also want it so that the comparison of the date is only year-month-day, so that you can then group the .
Long time; // System.currentTimeInMillis()
Map<Date, Integer>
stream().map()Collectors.groupBy()
Actually, the question is - is there a ready-made class that stores only the date (without time) and / or which implements equals taking into account the date without time. Or do you have to write your own wrapper?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2018-03-14
@piatachki

Unix-time - you mean the number of ml.sec. from 01/01/1970?
Then just divide the value by the number of milliseconds in a day (86400000) to get the same unix-time in days only.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question