Javascript CountDown在Firefox上显示NaN

时间:2016-06-08 10:45:24

标签: javascript php jquery

我一直在研究从本地数据库中检索start_dateend_date的costum Javascript Countdown。 日期计数可由Google Chrome正常运行,但在Firefox和Opera中,它只是显示NaN

这是我用php的jquery。任何人都可以告诉我我的代码有什么问题吗?

这是在firefox和opera上显示的内容:

<?php

    include("connect.php");
    $query="select * from account where Account_No='".$_SESSION['Account_No']."' ";
    $rownum=mysql_query($query);


    while($row = mysql_fetch_array($rownum))
     {  
    $End_Time=$row['End_Time'];
     }
    $End = strtotime($End_Time); 
    $Year = date("y",$End);
    $Month = date("m",$End);
    $Day = date("d",$End);
    $Hour = date("H",$End);
    $Minute = date("i",$End); 
    ?>
    <script type="text/javascript" >
    var current="License has expired!";
    var year= <?php echo $Year; ?>;
    var month= <?php echo $Month; ?>;
    var day= <?php echo $Day; ?>;
    var hour= <?php echo $Hour; ?>;
    var minute= <?php echo $Minute; ?>;
    var tz=-5;



    var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

    function countdown(yr,m,d,hr,min){
        theyear=yr;themonth=m;theday=d;thehour=hr;theminute=min;
        var today=new Date();
        var todayy=today.getYear();
        if (todayy < 1000) {
        todayy+=1900; }
        var todaym=today.getMonth();
        var todayd=today.getDate();
        var todayh=today.getHours();
        var todaymin=today.getMinutes();
        var todaysec=today.getSeconds();
        var todaystring1=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
        var todaystring=Date.parse(todaystring1)+(tz*1000*60*60);
        var futurestring1=(montharray[m-1]+" "+d+", "+yr+" "+hr+":"+min);
        var futurestring=Date.parse(futurestring1)-(today.getTimezoneOffset()*(1000*60));
        var dd=futurestring-todaystring;
        var dday=Math.floor(dd/(60*60*1000*24)*1);
        var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
        var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
        var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
        if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){
            document.getElementById('count2').innerHTML=current;
            document.getElementById('count2').style.display="inline";
            document.getElementById('count2').style.width="390px";
            document.getElementById('dday').style.display="none";
            document.getElementById('dhour').style.display="none";
            document.getElementById('dmin').style.display="none";
            document.getElementById('dsec').style.display="none";
            document.getElementById('days').style.display="none";
            document.getElementById('hours').style.display="none";
            document.getElementById('minutes').style.display="none";
            document.getElementById('seconds').style.display="none";
            return;
        }
        else {
            document.getElementById('count2').style.display="none";
            document.getElementById('dday').innerHTML=dday;
            document.getElementById('dhour').innerHTML=dhour;
            document.getElementById('dmin').innerHTML=dmin;
            document.getElementById('dsec').innerHTML=dsec;
            setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000);
        }
    }
    </script>
<?php
    echo "License will exprie after : <br>
    <div id='forms'>
        <div class='numbers' id='count2' style='position: absolute; top: 10px; height: 60px; padding: 15px 0 0 10px; background-color: #000000; z-index: 20;'></div>
        <img src='images/bkgdimage.gif' class='background' style='position: absolute; left: 69px; top: 12px;'/>
        <img src='images/line.jpg' class='line' style='position: absolute; left: 69px; top: 40px;'/> 
        <div class='numbers' id='dday' style='position: absolute; left: 69px; top: 21px;' ></div>

        <img src='images/bkgdimage.gif' class='background' style='position: absolute; left: 141px; top: 12px;'/>
        <img src='images/line.jpg' class='line' style='position: absolute; left: 141px; top: 40px;'/>
        <div class='numbers' id='dhour' style='position: absolute; left: 141px; top: 21px;' ></div>

        <img src='images/bkgdimage.gif' class='background' style='position: absolute; left: 213px; top: 12px;'/>
        <img src='images/line.jpg' class='line' style='position: absolute; left: 213px; top: 40px;'/>
        <div class='numbers' id='dmin' style='position: absolute; left: 213px; top: 21px;' ></div>

        <img src='images/bkgdimage.gif' class='background' style='position: absolute; left: 285px; top: 12px;'/>
        <img src='images/line.jpg' class='line' style='position: absolute; left: 285px; top: 40px;'/>
        <div class='numbers' id='dsec' style='position: absolute; left: 285px; top: 21px;' ></div>

        <div class='title' id='days' style='position: absolute; left: 66px; top: 73px;' >Days</div>
        <div class='title' id='hours' style='position: absolute; left: 138px; top: 73px;' >Hours</div>
        <div class='title' id='minutes' style='position: absolute; left: 210px; top: 73px;' >Minutes</div>
        <div class='title' id='seconds' style='position: absolute; left: 282px; top: 73px;' >Seconds</div>
    </div>";
?>

1 个答案:

答案 0 :(得分:0)

Firefox不会解析年份为YY格式的日期。请改用YYYY,因此在代码中应替换

$Year = date("y",$End);

$Year = date("Y",$End);