开发者

PHP - date() not safe? what do I use?

I get the following warning in my PHP error log:

PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those met开发者_C百科hods and you are still getting this warning, you most likely misspelled the timezone identifier.

So, what do I use instead of or with date()?


You still use date. What's not safe is to rely on the system's timezone settings.

It says you should explicitly set your timezone in your script using date_default_timezone_set.


What was unclear in the warning?

It is not safe to rely on the system's timezone settings.

Set the timezone in your config:

date_default_timezone_set("Europe/Riga"); 

..for example.


You get it wrong:

It is not safe to rely on the system's timezone settings.

There is no problem with date() at all, but you should not rely on what your system tells you. Just set your prefered default time zone.


Set a timezone before you use the date function. You are on the web which is "everywhere". So, you should respect the time your user is on (Japan or Mexico).

Or set a default timezone using:

date_default_timezone_set('Australia/Queensland')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜