I have a simple script to convert a timestamp to a readable date, the basics of which is: date(“m/d/Y H:i:s”, $_POST[‘timestamp’])
This script is on a linux server in the US with PHP 5.2.16 and on my local Windows machine in NZ on PHP 5.3.0
When I enter the timestamp 1296471600 into these, I get the following results:
US server: 01/31/2011 05:00:00
NZ server: 02/01/2011 00:00:00
Why do I get different dates? Is it a locale issue? What would I need to do to get my local server to produce the same date as the US one?
It’s not so much a locale issue, as the two servers using different time zones. They are likely something similar to America/Chicago
for the US server and maybe Pacific/Auckland
for at home (or their sucky GMT+/-hours counterparts).
If you want to make your local PHP behave like your US server, then the first step is to find out which time zone the latter is using. To do that, just run a simple script like <?php echo [date_default_timezone_get()](http://php.net/date_default_timeonze_get); ?>
which should output the time zone being used.
Then, make your local PHP use that time zone by editing its php.ini file (make a [phpinfo()
page if you don’t know where it is) and set the [url=http://php.net/datetime.configuration]date.timezone](http://php.net/phpinfo)
setting to be whatever your US server said, for example date.timezone = America/Chicago
Thanks for your advice, Salathe. I will give that a try.