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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵