• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP+JS] Hourly countdown (With SERVER TIME!)

MappingFOR

Web Developer
Joined
Jul 12, 2010
Messages
35
Reaction score
0
Create a "countdown.php" in "layout.php" folder.

Code:
<?php

header("Content-type: text/javascript");

$date = date('M d Y H:i:s');

print 'var now = new Date("'.$date.'");';
print 'function times() {
now.setSeconds(now.getSeconds()+1);
lat = new Date("0 0 0 20:00:00"); // SET TIME (it's generally 20)
var hour1        = now.getHours();
var minute1      = now.getMinutes();
var second1      = now.getSeconds();

var hour2        = lat.getHours() - 1;
var minute2      = lat.getMinutes() - 1;
var second2      = lat.getSeconds();


if(hour2 >= hour1){ 
hours = hour2 - hour1;
}else{
hours = 24 - (hour1 - hour2);
}

minutes = 60 - minute1;
seconds = 60 - second1;

   if (hours   < 10) { hours   = "0" + hours;   }
   if (minutes < 10) { minutes = "0" + minutes; }
   if (seconds < 10) { seconds = "0" + seconds; }
   if (hours   > 23) { hours   = "23";   }
   if (minutes > 59) { minutes = "59"; }
   if (seconds > 59) { seconds = "59"; }
document.getElementById("hours").innerHTML = hours;
document.getElementById("minutes").innerHTML = minutes;
document.getElementById("seconds").innerHTML = seconds;
}

var animeInt;
clearInterval(animeInt);
animeInt = setInterval("times()", 1000);';

?>

Put that code in acc layout head:

Code:
<script src="countdown.php" type="text/javascript"></script>

Now, just place a text into site.

PL
Code:
<?php
$lang['pl']['time'] = "Do startu serwera pozostało: %s godzin %s minut %s sekund.";
printf($lang['pl']['time'],'<span id="hours"></span>','<span id="minutes"></span>','<span id="seconds"></span>');
?>

US
Code:
<?php
$lang['us']['time'] = "To server start remain: %s hours %s minutes %s seconds.";
printf($lang['pl']['time'],'<span id="hours"></span>','<span id="minutes"></span>','<span id="seconds"></span>'); ?>



+ The same time for all ppl.
 
Try change
Code:
<script src="countdown.php" type="text/javascript"></script>
to
Code:
<script src="layouts\[layoutname]\countdown.php" type="text/javascript"></script>
 
I know what happen! You must delete comment:
"// SET TIME (it's generally 20)"
OR change it to:
"// SET TIME (it\'s generally 20)"

AND good form is:
"<script src="/layouts/tibiacom/countdown.php" type="text/javascript"></script>"
 
mm, no, not really <_<

@on topic
you don't have to use php for date, it can be done by using Date without arguments:
Code:
var now = new Date();

But then it'll be different time for different timezones? :p
 
I don't get it exactly where to put the shit, I managed to know where to put countdown.php but the other, where the heck do I put these? >_<
 
Put that code in acc layout head:

Code:

<script src="countdown.php" type="text/javascript"></script>

hello, where can i find this ^?
 
where i put it
PHP:
<?php
$lang['us']['time'] = "To server start remain: %s hours %s minutes %s seconds.";
printf($lang['pl']['time'],'<span id="hours"></span>','<span id="minutes"></span>','<span id="seconds"></span>'); ?>
 
Back
Top