saifudeen ni saifudeen ni - 1 month ago 8
Javascript Question

Javascript countdown timer error when loading

I have javascript code for timer countdown. Present output is, the second digits are decreasing from 60 to 0, but when seconds digits reaches 0, the minute digits are not decreasing. I have added a jsfiddle below, please help me.
jsFiddle: https://jsfiddle.net/jyv3gLup/

My javaScript code is added below,

function getDifferenceTime(){
var deadline= Date.parse(new Date("2016-11-1T05:00:00"));
var difval= deadline- Date.parse(new Date());
var days= Math.floor(difval/(1000*60*60*24));
var hours= Math.floor( (difval/(1000*60*60))%24);
var minutes= Math.floor( (difval/(1000/60))%60);
var seconds= Math.floor( (difval/1000)%60);
document.getElementById("tes").innerHTML= days + "Days and " +hours + "hours and " + minutes + " Minutes and" + seconds;

}
getDifferenceTime();
setInterval(getDifferenceTime, 1000);

Answer

function getDifferenceTime(){
 var deadline= Date.parse(new    Date("2016-11-1T05:00:00"));
  var diff_val= deadline- Date.parse(new Date());
  var days= Math.floor(diff_val/(1000*60*60*24));
  var hours= Math.floor((diff_val/(1000*60*60))%24);
  var minutes= Math.floor((diff_val/(1000*60))%60);
  var seconds= Math.floor((diff_val/1000)%60);									document.getElementById("date_test").innerHTML= days + "Days and " +hours + "hours and " + minutes + " Minutes  and"  + seconds;	
								}// function close
                
getDifferenceTime();
								setInterval(getDifferenceTime, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<div id="date_test"></div>

Here is JSFiddle