PHP Timezone different then Centos date
I'm having some issues with my php script. For some reason the date function gives a totally different time then my servers date function.
For instance php date gives me:
Saturday 28th of March 2015 01:05:12 AM
While centos date gives me:
Fri Mar 27 18:05:12 PDT 2015
I noticed the issue because my contab's which are scheduled to run at midnight are running at the wrong time despite the server date time being correct.
I don't understand whats going on because this was working fine up until a few days ago.
The "totally different time" is really the same time, expressed in a different timezone.
CentOS "PDT" is indicating Pacific Daylight Time. PHP is showing the time 7 hours ahead, which is "UTC" or "GMT", basically the "no time zone" time zone.
Look in your /etc/php.ini
file for a line like this:
date.timezone = UTC
More information and available timezones are shown here: http://php.net/manual/en/datetime.configuration.php#ini.date.timezone
If you want to change the timezone for CentOS itself, you can look up more info on the /etc/sysconfig/clock
file.
I actually encourage you to keep everything in UTC, as it avoids all TZ issues altogether, at the slight cost of a little mental arithmetic when you edit your crontab files.
链接地址: http://www.djcxy.com/p/59022.html上一篇: 日期减去秒总是返回相同
下一篇: PHP时区与Centos日期不同