问题
I searched now for many hours, it seem's like nobody got that problem before.
I run a script, which writes the current timestamp into a database, on two servers. Both have the same os, software, ... and the same timezone.
Now I found out, that the diff between some timestamps and the current time() is a negative number (yes, the calculation is correct: time() - $older_timestamp
)
I dumped time() on both servers, the result: it differs by exactly one hour. Check it out:
- time() on server #1: -1 hour
- time() on server #2: correct timestamp
Since time() should be always UTC-based, I can not explain, how this happens.
Does someone have any idea?
Greetings from Aachen
回答1:
Apparently server one and server two are set to different times. Check BIOS and your servers' OS time.
回答2:
To add to the merry fest, I give you another option.
The OS' Time-Zone might be set incorrectly. If both clocks show the same time but one server thinks it is in London while the other thinks it is in Aachen, the UTC time returned from the system call will differ by one hour.
If you would however install say NTPD
none of this would happen. (usually)
回答3:
This is likely caused by the timezone being incorrectly set in the php.ini
for Apache. Check the php.ini
file for date.timezone =
and change it to your timezone. A list of PHP timezones can be found here: http://php.net/manual/en/timezones.php
For example:
date.timezone = 'America/Chicago'
You may also be able to use an ini_set if you cannot edit the php.ini
file directly.
ini_set('date.timezone', 'America/Chicago');
来源:https://stackoverflow.com/questions/13978567/time-returns-different-timestamps-based-on-server