PHP - date () vs. date.timezone / date_default_timezone_set ()

I just got a new computer, and I was setting up PHP / MySQL / databases, etc. I think I'm just there, except that he threw this curved ball. My script login worked fine, but now it spits out the following warning (which will ruin JSON).

Warning : date () [function.date]: You cannot rely on the system time zone settings. You need to use the date.timezone parameter or the date_default_timezone_set () function. If you used any of these methods, and you still receive this warning, you most likely specified the time zone identifier with an error. We chose Antarctica / Macquarie for 'EST / 10.0 / no DST' instead of ... / php / login.php online 47

My code clearly uses date()and works in the live version and on the old machine. I get two warnings for the following two lines of code:

$date = date("ymd");

$this_year = date("y");

My research (see here ) shows that the behavior of these functions depends on php.ini.

php.ini , - , date()

.

+5
4

php.ini, date_default_timezone_set(). , .

- , ( ):

date_default_timezone_set('America/Los_Angeles');
+11
+4

-, , , , .

date_default_timezone_set('Your/Timezone');

php.ini,

[Date]
; ...
; ...
date.timezone = Your/Timezone
+4

php.ini.

However, if you have the time zone that you will use for most of your php files by adding the following line to your php.ini, you should do the trick.

date.timezone = "Your/Timezone"

In my case, I added the following line in php.ini. Personally, I prefer to store all our servers in the UTC time zone.

date.timezone = "UTC"
+4
source

All Articles