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 getDateOfTimeStamp(time) {
var originTime = 0;
var offsetOriginTime = originTime + new Date().getTimezoneOffset() * 60 * 1000;
var timeSinceOrigin = time - offsetOriginTime;
var timeModulo = timeSinceOrigin % (24 * 60 * 60 * 1000);
var normalizedTime = time - timeModulo;
console.log(new Date(normalizedTime) ,new Date(time));
return normalizedTime;
}
This worked for my project. Pure math, no string manipulation needed, no external lib needed, so it's super fast.
You can try by copying the above function to javascript console and then do normalizeTimeToDate(Date.now())