The following script is returning the wrong time after I call date_default_timezone_set("UTC")
<?PHP
$timestamp = time();
echo "<p>Timestamp: $timestamp</p>";
// This returns the correct time
echo "<p>". date("Y-m-d H:i:s", $timestamp) ."</p>";
echo "<p>Now I call 'date_default_timezone_set(\"UTC\")' and echo out the same timestamp.</p>";
echo "Set timezone = " . date_default_timezone_set("UTC");
// This returns a time 5 hours in the past
echo "<p>". date("Y-m-d H:i:s", $timestamp) ."</p>";
?>
The timezone on the server is BST. So what should happen is that the second call to 'date' should return a time 1 hour behind the first call. It's actually returning a time 5 hours behind the first one.
I should note that the server was originally set up with the EDT timezone (UTC -4). That was changed to BST (UTC +1) and the server was restarted.
I can't figure out if this is a PHP problem or a problem with the server.
just set your region with following code
date_default_timezone_set("Asia/Bangkok");//set you countary name from below timezone list
echo $date = date("Y-m-d H:i:s", time());//now it will show "Asia/Bangkok" or your date time
List of Supported Timezones http://www.php.net/manual/en/timezones.php
This is almost certainly not an error in php, but in your local timezone configuration.
Most likely, you didn't actually change the system-wide time zone, but only that of an interactive display. Check that /etc/localtime
matches what you'd expect. On debian systems, you can run tzselect (with superuser privileges) to set the system-wide timezone.
After setting the timezone, you may have to reset your clock. On many systems, that should happen automatically over time, but you can do it manually by running ntpdate -u pool.ntp.org
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With