Hey,
I'm having a problem with some date calculations and can't figure out whats going on. I have a service that returns an array of responses. Each response contains fields from the users collection including the _updatedAtField. I have the value of that field mapped to a label on the page. I then have the following javascript code processing the value:
var curTime = new Date();
var curTimesec = Date.parse(curTime);
var updateTime = new Date(value);
var updateTimesec = Date.parse(updateTime);
var dif = curTimesec - updateTimesec;
Code: Select all
if (dif < 1000){
return '1 second ago';
}
else if (dif < 60000){
var sec = dif/1000;
return Math.round(sec) + ' seconds ago';
}
else if (dif < 3600000){
var min = dif/60000;
if (min < 86400000){
var hours = dif/3600000;
if (hours< 2){
return Math.round(days) + ' day ago';
}
else{
return Math.round(days) + ' days ago';
}
}
Everything seems to work correctly except the time difference is three hours off. I've tried everything I can think of but not able to get this to work correctly. Any advice would be greatly appreciated. THANKS!