我的时间倒计时脚本在谷歌浏览器中工作正常,但在其他浏览器中打开时它显示为南楠


My time countdown script is working fine in Google Chrome but it appears Nan Nan when opened in other browser

<? 
include("commonfile.php");
$start = date("Y-m-d H:i:s");
$end = $_POST['date']." ".$_POST['time'];
if(isset($_POST['productid']) && $_POST['productid']!=""){
    $productid = $_POST['productid'];
    $expdata = getdata("SELECT expire_date,expire_time from tbl_listing_master WHERE listingid=".$productid." AND currentstatus=0");    
    $time_rs = mysql_fetch_array($expdata);
    $expdate = $time_rs[0];
    $exptime = $time_rs[1];
    $end = $expdate." ".$exptime;
}
$n = array("expdate" => $end); 
echo json_encode($n);  
?>

这是我正在使用的倒计时版本http://keith-wood.name/countdown.html jQuery v1.6.0 的倒计时。

问题是你的日期解析(我从你的 dup 问题的链接中抓取了这段代码(。

function updateCountdown(el, date, time, productId) {
    $.ajax({
      type: "POST",
      url: "../coding/fetch_time_forquery.php",
      dataType: "json",
      data: {date: date, time: time, productid: productId },
      success: function(data)
      {
        newYear = new Date (data.expdate);
         $(el).countdown({until:newYear} );
      }
    });
}

您需要在此处解析日期:newYear = new Date (data.expdate);,但从 php 返回的格式2012-08-31 2:33:35.。如果您只返回时间戳会更容易。

要在PHP中执行此操作,您需要将$end转换为时间戳而不是字符串:

$n = array("expdate" => strtotime($end) . '000' ); // add milliseconds

在 js 中:

newYear = new Date ( parseInt( data.expdate, 10 ) );

应该工作