I'm struggling to display a running clock with commas, especially for milliseconds. I'm trying to show the continuous amount of time passed between a given date (a wedding day) and now, basically something like:
5 Years
2,035 days
48,845 hours
2,930,722 minutes
175,843,367 seconds
175,843,428,554 milliseconds
I've got some JQuery that displays the running time without issues, but it displays this without the commas (so 48845 hours instead of 48,845 hours, or 175843428554 milliseconds instead of 175,843,428,554 milliseconds). How can I format this?
My code is:
function myFunction(){
var timeStart = new Date("Sat Oct 15 2016 13:00:00 GMT+0100").getTime();
var timeEnd = new Date();
var mDiff = timeEnd - timeStart; //in milliseconds
var secondDiff = Math.floor(mDiff / 1000); //in seconds
var minuteDiff = Math.floor(mDiff / 60 / 1000); //in minutes
var hourDiff = Math.floor(mDiff / 3600 / 1000); // in hours
var dayDiff = Math.floor(mDiff / 24 / 3600 / 1000); // in days
var yearDiff = Math.floor(mDiff / 365 / 24 / 3600/ 1000);
document.getElementById("second").innerHTML = secondDiff;
document.getElementById("minutes").innerHTML = minuteDiff;
document.getElementById("hours").innerHTML = hourDiff;
document.getElementById("days").innerHTML = dayDiff;
//document.getElementById("weeks").innerHTML = secondDiff;
document.getElementById("years").innerHTML = yearDiff;
}
setInterval(myFunction, 1000);