Javascript Date countDown(withDays)

Description

Javascript Date countDown(withDays)


Date.prototype.countDown = function(withDays){
    addDays = (typeof withDays === 'undefined') ? true : withDays;
    //  w ww . j  a va2 s .c o  m
 var timeLeft = (this/1000) - ((new Date())/1000)
 var days, hours, minutes, seconds;
    var timeArray = []

    if(addDays){
    days = parseInt(timeLeft/86400)
       timeArray.push(days)
    timeLeft = timeLeft % 86400
    }
    
 hours = parseInt(timeLeft/3600)
    timeArray.push(hours)
 timeLeft = timeLeft % 3600
 minutes = parseInt(timeLeft/60)
    timeArray.push(minutes)
 seconds = parseInt(timeLeft % 60)
    timeArray.push(seconds)

 return timeArray
}



PreviousNext

Related