2

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:

<?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>

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:

<?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>
deerox
  • 1,045
  • 3
  • 14
  • 28

2 Answers2

4

To get GMT/UTC date-time values, use gmdate instead of date.

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

The date function does two things:

First, it converts the Unix Timestamp (which is a UTC value anyway) into the computer local timezone.
Secondly it then converts this local value into a string representation using the supplied format string.

The gmdate function, on the other hand, merely creates a string representation without doing any timezone conversion.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • `$targetDateDisplay = gmdate($dateFormat,$targetDate); $actualDateDisplay = gmdate($dateFormat,$actualDate);` another issue came out after fixing this : `Target date: 2012-09-26 14:00:00` even i have set : $targetDate = mktime(15,00,00,9,26,2012); – deerox Sep 26 '12 at 05:40
  • Please update your original question with details of the new problem you're experiencing. – Dai Sep 26 '12 at 05:47
2

For your second issue, I guess that a gmmktime instead of mktime will suits your needs (you should have a look to the documentation here).

Samuel Caillerie
  • 8,259
  • 1
  • 27
  • 33