I have three different pages using the same code to get the time for a countdown clock. The clock counts down to midnight.
The second and third pages are showing the same time counting down, but the homepage is showing a different time. It’s all the same code and I included this PHP files on each of the pages:
<script>
jQuery(document).ready(function() {
$('#countdown_dashboard').countDown({
serverDate: {
'day': <?php echo date("j"); ?>,
'month': <?php echo date("n"); ?>,
'year': <?php echo date("Y"); ?>,
'hour': 24,
'min': 0,
'sec': 0,
'serverDay': <?php echo date("j"); ?>,
'serverMonth': <?php echo date("n"); ?>,
'serverYear': <?php echo date("Y"); ?>,
'serverHour': <?php echo date("G"); ?>,
'serverMin': <?php echo date("i"); ?>,
'serverSec': <?php echo date("s"); ?>
},
omitWeeks: true
});
});
</script>
What do I need to change to make the homepage timer match up with the others?
It looks like the homepage is providing a time that is +4 hours off from the other two links you provided. This would indicate to me that the homepage script is using a different timezone setting than the other two links.
PHP has an internal timezone setting called
date.timezonethat is affected by php.ini and can be changed at run-time with the date_default_timezone_set() function. Most of PHP’s date/time functions like the one you’re using date, are affected by this timezone setting.You can add a call to phpinfo() in each of those scripts, and it will output all of the loaded configuration directives for those scripts and that can help you figure out which timezone is currently being used for each one. Note that if the timezone is left blank different versions of PHP behave differently. Older versions of PHP (pre PHP 5.4) used to try and guess your system’s timezone setting, whereas in PHP 5.4+ it will just default to UTC.