javascript - Date difference larger than intended -
i learning use date object in javascript. tried calculate difference between , set date, returns larger value inteded. codepen here, can't seem figure did wrong... help?
var setdate = new date(2014, 4, 27, 14,30); //27th of april year @ 14:30 var = new date(); //now, whenever code runs var diff = math.round((setdate.gettime() - now.gettime())/1000); //difference in seconds function nicetimer(delta) { //decompose difference in seconds date units. this.days = math.floor(delta/ 86400); delta -= this.days*86400; //subtract value once has been "extracted". this.hours = math.floor(delta/ 3600); delta -= this.hours*3600; this.minutes = math.floor(delta/ 60); delta -= this.minutes*60; this.seconds = delta; this.printstring = function() { return "the event starts in "+this.days+" days, "+this.hours+" hours, "+this.minutes+" minutes , "+this.seconds+" seconds"; //output readable countdown string } } var timer = new nicetimer(diff); var el = document.getelementbyid("timer"); el.innerhtml = timer.printstring();
var setdate = new date(2014, 4, 27, 14,30); //27th of april year @ 14:30
change 4 three, months start @ index zero.
var setdate = new date(2014, 3, 27, 14,30);
month integer value representing month, beginning 0 january 11 december.
Comments
Post a Comment