I have a problem with PHP not reflecting correctly the actual time, an as a result all server's scripts are always 5 hours in the future.

If I run this in thecommand line I got. (Centos5) ..

[root@server ~]# date
Sat May  4 11:20:17 CDT 2013

Which is correct (Im from mexico and the server has the correct Time Zone and time set), how ever doing this in PHP I get...

[root@server ~]# php -r 'echo gmdate("D, d M Y H:i:s e")."\n";'
Sat, 04 May 2013 16:18:45 UTC

As you can see the time is hours in the future, and my php.ini is supposed to have also the correct time zone defined.

[Date]
; Defines the default timezone used by the date functions
date.timezone = America/Mexico_City

So what can be the problem here?

有帮助吗?

解决方案

gmdate() returns the time according to GMT (Greenwich Mean Time) which (although not the same) is used interchangeably with UTC. You said that right now you're in CDT which is 5 hours behind UTC (because Daylight Savings Time is in effect).

If you want your scripts to generate datetime strings which reflect the time zone set in your php.ini file you should use the date() function. Better yet, start using the DateTime library.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top