Last Updated: February 25, 2016
·
477
· khay

Count Total Time Difference in Y/M/D H:M:S

This is just a simple script to count total time difference from one fixed date to current time. Or, you can also use as both fixed dates.

HTML Structure

<span id="time"></span>

Script

$(function(){
    var calcNewYear = setInterval(function(){
    todayDate = new Date();
    secondDate = new Date("August 14, 2013 18:00:00");           

    seconds = Math.floor((todayDate - (secondDate))/1000);
    minutes = Math.floor(seconds/60);
    hours = Math.floor(minutes/60);
    days = Math.floor(hours/24);

    hours = hours-(days*24);
    minutes = minutes-(days*24*60)-(hours*60);
    seconds = seconds-(days*24*60*60)-(hours*60*60)-(minutes*60);

    $("#time").text(days +" days, "+ hours + " hours, " + minutes + " minutes and " + seconds + " Seconds.");
        },1000);
});