gpt4 book ai didi

php - 倒数计时器不适用于 gmt 时间

转载 作者:太空宇宙 更新时间:2023-11-04 14:43:05 25 4
gpt4 key购买 nike

我有倒计时,不占用 GMT 时间。

我希望它有 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 小时:输出:

Target date: 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>

最佳答案

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

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

date 函数做了两件事:

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

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

关于php - 倒数计时器不适用于 gmt 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12594438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com