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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘