PHP / Javascript倒计时脚本

注意*我想要一个人来解决它,并告诉我他们是如何做到的,不是关于如何做到这一点的技巧或者关于php和java混合的coments *

我有一个正在运行的倒计时脚本,但是当它达到目标日期时,计时器继续进入负时间.我希望它在目标日期停止并只显示完成消息.它存在于我的网站上.我只需要帮助编辑倒计时脚本.

我想保持相同的布局.我需要一些帮助添加完成消息并阻止它进入否定日期,或者只是让它不显示0days,0小时,0分钟,0秒直到网站正式发布.当这最终发生时,我希望它显示一条消息.

倒计时脚本

<?php date_default_timezone_set('EST'); ?>
<?php
// Define your target date here
    $targetYear  = 2011;
    $targetMonth = 9;
    $targetDay   = 1;
    $targetHour  = 20;
    $targetMinute= 00;
    $targetSecond= 00;
// End target date definition

// Define date format
$dateFormat = "Y-m-d H:i:s";

$targetDate = mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear);
$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 = date($dateFormat,$targetDate);
$actualDateDisplay = date($dateFormat,$actualDate);

?>
<script type="text/javascript">
  var days = <?php echo $remainingDay; ?>  
  var hours = <?php echo $remainingHour; ?>  
  var minutes = <?php echo $remainingMinutes; ?>  
  var seconds = <?php echo $remainingSeconds; ?>  
</script>
<body onl oad="setCountDown();">
<center><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes and $remainingSeconds seconds";?> untill official release</center>

它是如何在网站上添加的

<script type="text/javascript">
$(function() {
    /* Union War */
    $("#Countdown2").load("http://imperialism.zxq.net/includes/process/uwcountdown.php");

    setInterval(function(){
        $("#Countdown2").load("http://imperialism.zxq.net/includes/process/uwcountdown.php");
    }, 1000);
});
</script>

<div id="uwCD" class="uwCD">
    <div id="Countdown2"></div>
</div>

解决方法:

if($targetDate != $actualDate && $targetDate > $actualDate) { 
echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes and $remainingSeconds seconds"; 
} else { 
echo "0 days, 0 hours, 0 minutes and 0 seconds"; 
} 
上一篇:榛子云短信-微信小程序60秒倒计时插件


下一篇:在PostgreSQL或MySQL中是否存在反向“AUTO_INCREMENT”的现有实现?