问题
The problem is that date('r') returns wrong time for my timezone.
php.ini timezone setting:
date.timezone = Europe/Kiev
date_default_timezone_set('Europe/Kiev') in my script solves the problem.
So what's wrong with WAMP?
回答1:
I suggest always using date_default_timezone_set() from script
e.g.
date_default_timezone_set('Europe/Kiev');
or
ini_set('date.timezone', 'Europe/Kiev');
...to avoid PHP guessing timezone.
It comes handy when you transfer code to different server(s), for example, outside of Ukraine. This line should help you to avoid unexpected (wrong) results if date.timezone
is not set in php.ini
or its setting is incorrect. It's also handy when you can't access and/or modify php.ini
(shared hosting).
Also, be sure that you've not used ;
at the and of line in php.ini
.
Restart server after changing php.ini
.
回答2:
Edit php.ini
and restart Apache:
- left click to WampServer in tray icon
- open
php.ini
(go to PHP -> php.ini) - set new
date.timezone
value
;date.timezone = UTC date.timezone = Europe/Kiev
- restart Apache ( go to Apache -> Service -> Restart Service )
- check value of
date.timezone
byphpinfo();
回答3:
You need to reload the configuration / restart the server after editing your php.ini file.
回答4:
According to the documentation of date_default_timezone_get, the date.timezone configuration option can be overridden by setting the TZ
environement variable (which, in turn, can be overridden by calling date_default_timezone_set). From your description, I suspect that the TZ
environement veriable is set.
回答5:
by default it shows GMT time you can change for 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
回答6:
I know this is an old question.
If you are using a PHP framework, you might want to check the config file of the framework. For example in Laravel, open the config/app.php
and you will find timezone there. Set it to your timezone.
回答7:
- Open your php.ini with maybe notepad++, sublime text...
- Add this line to the file: date.timezone = "X" Where X is the your time-zone of wish. Get a list of supported timezones here: http://php.net/manual/en/timezones.php
... That should do it. 3. Restart your server
来源:https://stackoverflow.com/questions/5753699/wrong-php-date-output-in-wamp-server