我有倒计时,这不是格林尼治标准时间。
我希望它有GMT时间。它似乎使用伦敦时间+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>
答案 0 :(得分:4)
要获取GMT / UTC日期时间值,请使用gmdate
代替date
。
$targetDateDisplay = gmdate($dateFormat,$targetDate);
$actualDateDisplay = gmdate($dateFormat,$actualDate);
date
函数执行两项操作:
首先,它将Unix时间戳(无论如何是UTC值)转换为计算机本地时区 然后,它使用提供的格式字符串将此本地值转换为字符串表示。
另一方面,gmdate
函数只是创建一个字符串表示而不进行任何时区转换。
答案 1 :(得分:2)
对于您的第二个问题,我认为gmmktime
代替mktime
符合您的需求(您应该查看文档here)。