Today in a project to do a countdown to the effect of their own JS level is very general, on the Internet to find a section of the countdown code used (as follows):
functionCountdown (jqueryobj) {varDay_elem = Jqueryobj.find ('. Day ')); varHour_elem = Jqueryobj.find ('. Hour ')); varMinute_elem = Jqueryobj.find ('. Minute ')); varSecond_elem = Jqueryobj.find ('. Second ')); varTime = Jqueryobj.data ("Endtime");varEnd_time =NewDate (Time). GetTime (),//month is the actual month-1Sys_second = (End_time-NewDate (). GetTime ())/1000; varTimer = SetInterval (function () { if(Sys_second > 1) {Sys_second-= 1; varDay = Math.floor ((sys_second/3600)/24); varhour = Math.floor ((sys_second/3600)% 24); varminute = Math.floor ((SYS_SECOND/60)% 60); varSecond = Math.floor (sys_second% 60); Day_elem&& $ (Day_elem). Text (day);//Calculate Days$ (Hour_elem). Text (Hour < 10?) "0" + hour:hour);//Calculation Hours$ (Minute_elem). Text (Minute < 10?) "0" + minute:minute);//Calculate minutes$ (Second_elem). Text (Second < 10?) "0" + second:second);//calculate seconds to kill}Else { varA_play = Jqueryobj.find ('. P_ljw A:first '); if(Time.length > 0) a_play.attr (' href ', ' javascript:void (0) '). addclass (' A_not '). Text (' Closed '); Clearinterval (timer); } }, 1000); }
Because I have been using chrome as the main browser, the development of testing is normal, but also did not think of browser compatibility issues, when this module on-line beta found a problem,var end_time = new Date (time). GetTime ( This line of code in Firefox, ie run after the value of End_time is NaN, where time is in the format of "Yyyy-mm-dd HH:mm:ss", Google made the following modifications, run normally, I call the solution one
Solution One
functionCountdown (jqueryobj) {varDay_elem = Jqueryobj.find ('. Day ')); varHour_elem = Jqueryobj.find ('. Hour ')); varMinute_elem = Jqueryobj.find ('. Minute ')); varSecond_elem = Jqueryobj.find ('. Second ')); varTime = Jqueryobj.data ("Endtime");
Modify-----------varDatetimearray = Time.split ("); varDatearray = Datetimearray[0].split ('-')); varTimearray = Datetimearray[1].split (': ')); varEnd_time =NewDate (Datearray[0], (datearray[1]-1), datearray[2],timearray[0],timearray[1],timearray[2]). GetTime (),//month is the actual month-1
Modify-----------Sys_second = (End_time-NewDate (). GetTime ())/1000; varTimer = SetInterval (function () { if(Sys_second > 1) {Sys_second-= 1; varDay = Math.floor ((sys_second/3600)/24); varhour = Math.floor ((sys_second/3600)% 24); varminute = Math.floor ((SYS_SECOND/60)% 60); varSecond = Math.floor (sys_second% 60); Day_elem&& $ (Day_elem). Text (day);//Calculate Days$ (Hour_elem). Text (Hour < 10?) "0" + hour:hour);//Calculation Hours$ (Minute_elem). Text (Minute < 10?) "0" + minute:minute);//Calculate minutes$ (Second_elem). Text (Second < 10?) "0" + second:second);//calculate seconds to kill}Else { varA_play = Jqueryobj.find ('. P_ljw A:first '); if(Time.length > 0) a_play.attr (' href ', ' javascript:void (0) '). addclass (' A_not '). Text (' Closed '); Clearinterval (timer); } }, 1000); }
Solution II
Plan two is to change the format of the date, the format of time from "Yyyy-mm-dd HH:mm:ss" to "Yyyy/mm/dd HH:mm:ss"
JS New Date (' Yyyy-mm-dd HH:mm:ss '). GetTime () solution for Nan under IE, ff