Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong PHP date() output in wamp server

Tags:

php

wampserver

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?

like image 914
anon Avatar asked Apr 22 '11 08:04

anon


2 Answers

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.

like image 93
Wh1T3h4Ck5 Avatar answered Nov 12 '22 19:11

Wh1T3h4Ck5


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 by phpinfo();
like image 6
Cendak Avatar answered Nov 12 '22 17:11

Cendak