JS New Date (' Yyyy-mm-dd HH:mm:ss '). GetTime () solution for Nan under IE, ff

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.