2

我有倒计时,它不占用格林威治标准时间。

我希望它有格林威治标准时间。它使用的伦敦时间似乎是+1。

现场演示: http: //ffsng.deewayz.in/countdown/

看来实际日期:有一些错误,或者我不知道它需要什么时间。我希望它采用 GMT 时间和日期

这是我的代码:

<?php
$dateFormat = "Y-m-d H:i:s";
$targetDate = mktime(15,00,00,9,26,2012);
$actualDate = time();
$secondsDiff = $targetDate - $actualDate;
$remainingDay     = floor($secondsDiff/60/60/24);
$remainingHour    = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
$targetDateDisplay = gmdate($dateFormat,$targetDate);
$actualDateDisplay = gmdate($dateFormat,$actualDate);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FFSng Raid Countdown</title>
<link rel="stylesheet" type="text/css" href="/countdown/css.css"/>
<link href="style/style.css" rel="stylesheet" type="text/css" />


<script type="text/javascript">
var days = <?php echo $remainingDay; ?>;
var hours = <?php echo $remainingHour; ?>;  
var minutes = <?php echo $remainingMinutes; ?>;  
var seconds = <?php echo $remainingSeconds; ?>;

function setCountDown ()
{
  seconds--;
  if (seconds < 0){
      minutes--;
      seconds = 59;
  }
  if (minutes < 0){
      hours--;
      minutes = 59;
  }
  if (hours < 0){
      days--;
      hours = 23;
  }
  document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
  setTimeout ( "setCountDown()", 1000 );
}
</script>


</head>
<center>
<body onload="setCountDown();">
<div id="container">
    <div id="header"><div id="header_left"></div>
    <div id="header_main"><span class="red"><h2>FFSng Raid Countdown</h2></span></div><div id="header_right"></div></div>
    <div id="content">
        <table class="countTable">
           <tr><td><span class="points">Target date:</td><td><?php echo $targetDateDisplay; ?></span></td></tr>
           <tr><th colspan="2" id="remain"><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></th></tr>
           <tr><td>Actual date:</td><td><?php echo $actualDateDisplay; ?></td></tr>
       </table>
    </div>
</div>
</body>
</center>
</html>

出现第二个问题

但现在它少了 1 小时: 输出:

目标日期:2012-09-26 14:00:00

但我已经设置

$targetDate = mktime(15,00,00,9,26,2012);

固定代码:

<?php
$dateFormat = "Y-m-d H:i:s";
$targetDate = gmmktime(15,00,00,9,26,2012);
$actualDate = time();
$secondsDiff = $targetDate - $actualDate;
$remainingDay     = floor($secondsDiff/60/60/24);
$remainingHour    = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
$targetDateDisplay = gmdate($dateFormat,$targetDate);
$actualDateDisplay = gmdate($dateFormat,$actualDate);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FFSng Raid Countdown</title>

<script type="text/javascript">
var days = <?php echo $remainingDay; ?>;
var hours = <?php echo $remainingHour; ?>;  
var minutes = <?php echo $remainingMinutes; ?>;  
var seconds = <?php echo $remainingSeconds; ?>;

function setCountDown ()
{
  seconds--;
  if (seconds < 0){
      minutes--;
      seconds = 59;
  }
  if (minutes < 0){
      hours--;
      minutes = 59;
  }
  if (hours < 0){
      days--;
      hours = 23;
  }
  document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
  setTimeout ( "setCountDown()", 1000 );
}
</script>


</head>
<center>
<body onload="setCountDown();">
<div id="container">
    <div id="header"><div id="header_left"></div>
    <div id="header_main"><span class="red"><h2>FFSng 100 token Raid Countdown</h2></span></div><div id="header_right"></div></div>
    <div id="content">
        <table class="countTable">
           <center><img src="http://ffsng.com/images/ffsng_big.gif" width="400" height="240"></center>
           <tr><td>Target time and date:</td><td><?php echo $targetDateDisplay; ?></td></tr>
           <tr><th colspan="2" id="remain"><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></th></tr>
           <tr><td>Actual time and date:</td><td><?php echo $actualDateDisplay; ?></td></tr>
       </table>
    </div>
</div>
</body>
</center>
</html>
4

2 回答 2

4

要获取 GMT/UTC 日期时间值,请使用gmdate而不是date.

$targetDateDisplay = gmdate($dateFormat,$targetDate);
$actualDateDisplay = gmdate($dateFormat,$actualDate);

date函数做了两件事:

首先,它将 Unix 时间戳(无论如何都是 UTC 值)转换为计算机本地时区。
其次,它然后使用提供的格式字符串将此本地值转换为字符串表示形式。

gmdate另一方面,该函数仅创建一个字符串表示,而不进行任何时区转换。

于 2012-09-26T04:41:05.963 回答
2

对于您的第二个问题,我猜 agmmktime而不是mktime将适合您的需求(您应该查看此处的文档)。

于 2012-09-26T06:15:08.290 回答