倒数计时器不与gmt时间一起使用 [英] Countdown timer not working with gmt time
问题描述
我有倒计时,没有采取GMT时间。
我希望它有GMT时间。看来它使用的伦敦时间是+1。
现场演示: http://ffsng.deewayz.in/countdown/
看来实际日期:有一些错误,或者我不知道它的时间服用。我希望它取得GMT时间和日期
以下是我的代码:
<?php
$ dateFormat =Ymd 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 // ENhttp://www.w3.org/TR/xhtml1/DTD/的xhtml1-transitional.dtd>
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> FFSng Raid Countdown< / title>
< link rel =stylesheettype =text / csshref =/ countdown / css.css/>
< link href =style / style.css =stylesheettype =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; ?取代;
函数setCountDown()
{
seconds--;
if(seconds <0){
minutes--;
秒= 59;
}
if(minutes <0){
hours--;
分钟= 59;
}
if(hours <0){
days--;
小时= 23; innerHTML = days +days,+小时+小时,+分钟+分钟,+秒+秒;
}
document.getElementById
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>目标日期:< / td>< td><?php echo $ targetDateDisplay; ?>< /跨度>< / TD>< / TR>
< tr>< th colspan =2id =remain><?php echo$ remainingDay days,$ remainingHour hours,$ remainingMinutes minutes,$ remainingSeconds seconds;?>< ; /第>< / TR>
< tr>< td>实际日期:< / 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 =Ymd 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 // ENhttp://www.w3.org/TR/xhtml1/DTD/的xhtml1-transitional.dtd>
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =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; ?取代;
函数setCountDown()
{
seconds--;
if(seconds <0){
minutes--;
秒= 59;
}
if(minutes <0){
hours--;
分钟= 59;
}
if(hours <0){
days--;
小时= 23; innerHTML = days +days,+小时+小时,+分钟+分钟,+秒+秒;
}
document.getElementById
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令牌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.gifwidth =400height =240>< / center>
< tr>< td>目标时间和日期:< / td>< td><?php echo $ targetDateDisplay; ?>< / TD>< / TR>
< tr>< th colspan =2id =remain><?php echo$ remainingDay days,$ remainingHour hours,$ remainingMinutes minutes,$ remainingSeconds seconds;?>< ; /第>< / TR>
< tr>< td>实际时间和日期:< / td>< td><?php echo $ actualDateDisplay; ?>< / TD>< / TR>
< / table>
< / div>
< / div>
< / body>
< / center>
< / html>
要获取GMT / UTC日期时间值,请使用 gmdate
而不是日期
。
$ targetDateDisplay = gmdate($ dateFormat,$ targetDate);
$ actualDateDisplay = gmdate($ dateFormat,$ actualDate);
首先,它将Unix Timestamp(无论如何是一个UTC值)转换为计算机本地时区。 另一方面, I have countdown which is not taking GMT time. i want it to have GMT time. It seems its using London time that is +1. live demo : http://ffsng.deewayz.in/countdown/ It seems Actual date: there has some bug or i dont know what time its taking. i want it to take GMT time and date Here is my codes: 2nd issue come up But now it giving 1 hour less:
Output : Target date: 2012-09-26 14:00:00 But i have set $targetDate = mktime(15,00,00,9,26,2012); Fixed code:
To get GMT/UTC date-time values, use The First, it converts the Unix Timestamp (which is a UTC value anyway) into the computer local timezone. The 这篇关于倒数计时器不与gmt时间一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
然后它将该本地值转换为使用提供的格式字符串的字符串表示形式。
gmdate
函数仅创建一个字符串表示而不做任何时区转换。<?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>
<?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>
gmdate
instead of date
.$targetDateDisplay = gmdate($dateFormat,$targetDate);
$actualDateDisplay = gmdate($dateFormat,$actualDate);
date
function does two things:
Secondly it then converts this local value into a string representation using the supplied format string.gmdate
function, on the other hand, merely creates a string representation without doing any timezone conversion.