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 \"tim
function roundDownDate(date) {
if (typeof date !== "object" || !date.getUTCMilliseconds) {
throw Error("Arg must be a Date object.");
}
var offsetMs = date.getTimezoneOffset() * 60 * 1000,
oneDayMs = 24 * 60 * 60 * 1000;
return new Date(Math.floor((date.getTime() - offsetMs) / oneDayMs) * oneDayMs + offsetMs);
};
This should work and is pretty fast.