Do a time countdown and find that the days are always incorrect.
JS Code:
1 //Define target Date2 varTargettime =NewDate ();3 4 //Target Date5Targettime.setfullyear (2015,5,1);6 7 //Target when8Targettime.sethours (12);9 Ten //Target points OneTargettime.setminutes (0); A - //Target seconds -Targettime.setseconds (0); the - //Target milliseconds -Targettime.setmilliseconds (0); - + //converted to milliseconds - varEndTime =Targettime.gettime (); + A //Defining Methods at functionGetcountdowntime () { - - //define the date and time that the parameter returns today - varNowtime =NewDate (); - - //Time Millisecond Difference in varCOUNTDOWNMS = EndTime-nowtime.gettime (); - to //Get the time difference + varCountdowndays = Math.floor (Countdownms/(1000 * 60 * 60 * 24 )); - the //To arrive at a time-hour difference * varCountdownh = Math.floor (Countdownms/(1000 * 60 * 60))% 24; $ Panax Notoginseng //To arrive at a time minute difference - varCOUNTDOWNM = Math.floor (Countdownms/(1000 * 60))% 60; the + //To get a time difference of seconds A varcountdowns = Math.floor (countdownms/1000)% 60; the } + } - $ $$ (document). Ready (function () { -Window.setinterval ("Getcountdowntime ()", 1000); -});
In the calculated number of days, the countdown is always different from the defined target date by about 30 days
// target date targettime.setfullyear (2015,5,1);
Here's the problem:
The three parameter of the setFullYear () method is Year,month,day, where month represents the number of months between 0~11.
So the target date of May 1, 2015 should be
// target date targettime.setfullyear (2015,4,1);
JS calculates the incorrect number of days for the two date and time difference