I need to group a bunch of items in my web app by date created.
Each item has an exact timestamp, e.g. 1417628530199
. I'm using Moment.js and its "time from now" feature to convert these raw timestamps into nice readable dates, e.g. 2 Days Ago
. I then want to use the readable date as a header for a group of items created on the same date.
The problem is that the raw timestamps are too specific - two items that are created on the same date but a minute apart will each have a unique timestamp. So I get a header for 2 Days Ago
with the first item underneath, then another header for 2 Days Ago
with the second item underneath, etc.
What's the best way to round the raw timestamps to the nearest date, so that any items created on the same date will have the exact same timestamp and thus can be grouped together?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…