dooid3005 2016-06-08 10:45
浏览 53
已采纳

Javascript CountDown在Firefox上显示NaN

I have been working on costum Javascript Countdown that retrieve start_date and end_date from localhost database.
The date count works correctly by Google Chrome, but in Firefox and Opera it just says NaN.

Here is my jquery with php. Can anybody tell me what's wrong with my code?

This is what shows on firefox and 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条回答 默认 最新

  • doubu7134 2016-06-08 10:59
    关注

    Firefox doesn't parse the date when year is in YY format. Use YYYY instead, so in your code you should replace

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

    with

    $Year = date("Y",$End);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥30 android百度地图SDK海量点显示标题
    • ¥15 windows导入environment.yml运行conda env create -f environment_win.yml命令报错
    • ¥15 这段代码可以正常运行,打包后无法执行,在执行for内容之前一直不断弹窗,请修改调整
    • ¥15 C语言判断有向图是否存在环路
    • ¥15 请问4.11到4.18以及4.27和4.29公式的具体推导过程是怎样的呢
    • ¥20 将resnet50中的卷积替换微ODConv动态卷积
    • ¥15 通过文本框输入商品信息点击按钮将商品信息列举出来点击加入购物车商品信息添加到表单中
    • ¥100 这是什么压缩算法?如何解压?
    • ¥20 upload上传实验报错500,如何解决?(操作系统-windows)
    • ¥15 谁知道 ShaderGraph 那个节点可以接入 Particle System -> Custom Data