So I have 2 dates
Current Date
Event Date
Which traces
Current Date: Mon Feb 9 14:45:43 GMT-0500 2009
Event Date: Mon Feb 9 15:32:51 GMT-0500 2009
Now what I am trying to do is compare those dates and output the difference.
Something like
“Posted 2 minutes ago”
or
“Posted 2 hours ago”
etc.
What I am doing should be simple but I am getting stuck somewhere and need some help.
eventMillisecs = eventDate.getTime ();
currentMillisecs = currentDate.getTime ();
msecs = eventMillisecs - currentMillisecs;
secs = Math.floor (msecs / 1000);// 1000 milliseconds make a second
mins = Math.floor (secs / 60);// 60 seconds make a minute
hours = Math.floor (mins / 60);// 60 minutes make a hour
days = Math.floor (hours / 24);// 24 hours make a second
msecs = (msecs % 1000);
secs = (secs % 60);
mins = (mins % 60);
//mins = Math.abs (mins - 60);
hours = (hours % 24);
I guess what I am confused about is what do I do with the msec variable since I am trying to get the difference in time? I am overthinking this task?
Thanks
D