I've tried different ways to get my timestamp to change at midnight to the next day, but I haven't had any luck. I am using Wordpress, and changed the default location to Mountain Time. I figured that these two would communicate together but I haven't had any luck.
<?php current_time(timestamp); echo date('l, F jS Y'); ?>
<?php ini_set('date.timezone', 'America/Denver');
echo date('l, F jS Y'); ?>
The first one I am trying now, and the second snippet is one I was using prior.
Its hard to debug this, since I have to wait until the night to see if the date changes early to the next day. Not optimal. I appreciate any help on this.
It seems that you don't have the timezone well configured in your server. Just output the full date and time, you don't have to wait for midnight to get the difference between the right and wrong hour.
Regarding time and timezone in php you have to know two facts:
Knowing this you can easily debug your program.
<?php
echo date('r').PHP_EOL;
// timezone not configured
// Wed, 02 Jan 2019 16:11:36 +0000
echo date('U').PHP_EOL;
// 1546445496
ini_set('date.timezone', 'America/Denver');
echo date('r').PHP_EOL;
// Wed, 02 Jan 2019 09:11:36 -0700
echo date('U').PHP_EOL;
// 1546445496 , same as above
From this point you have many solutions, I recommend the following two:
Put this in your php.ini file:
date.timezone="America/Denver"
If you cannot edit the php.ini, use the DateTime object to convert it manually.
$d = new DateTime();
$d->setTimezone(new DateTimeZone('America/Denver'));
echo $d->format('r').PHP_EOL;
// Wed, 02 Jan 2019 09:11:36 -0700
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments