PHP-date()与date.timezone / date_default_timezone_set() [英] PHP - date() vs. date.timezone / date_default_timezone_set()

查看:110
本文介绍了PHP-date()与date.timezone / date_default_timezone_set()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚有一台新计算机,并且正在设置PHP / MySQL /数据库等。我想我就在那儿,除了扔了这个曲线球。我的登录脚本运行正常,但是现在它会吐出以下警告(使JSON混乱)。

I've just got a new computer, and I've been setting up PHP/MySQL/databases etc... I think I'm just about there, except it's thrown this curveball. My login script was working fine, but now it's spitting the following warning (which messes up the JSON).


警告:date()[function.date]:
依靠系统的时区设置并不安全。您需要
使用date.timezone设置或date_default_timezone_set()函数。如果您使用了这些
方法中的任何一种,但仍收到此警告,则很可能
拼写了时区标识符。我们在 ... / php / login.php 中的
47 上将'Antarctica / Macquarie'
选为'EST / 10.0 / no DST'。 b>

Warning: date() [function.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 methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Antarctica/Macquarie' for 'EST/10.0/no DST' instead in .../php/login.php on line 47

我的代码显然使用了 date()和在实时版本和旧计算机上均可运行。对于以下两行代码,我会收到两个警告:

My code obviously uses date() and is working 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");

我的研究(请参见此处)表明这些功能的行为取决于php.ini。

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

所以我应该在新机器上更改php.ini,还是我使用某种不赞成使用的方法,并且应该放弃 date() 总共?

So should I change php.ini on the new machine, or am I using some kind of deprecated method, and should I ditch date() altogether?

谢谢。

推荐答案

如果您使用 <$,则无需更改php.ini文件。 c $ c> date_default_timezone_set() 。只需将其设置为您将要工作的时区即可。

You don't need to change the php.ini file if you use date_default_timezone_set(). Just set it to the timezone you will be working in.

类似的内容应该放在配置文件中或在您使用日期的页面上(如果有的话)仅一页):

Something like this should go in a config file or on the page where you're working with dates (if it is only one page):

date_default_timezone_set('America/Los_Angeles');

这篇关于PHP-date()与date.timezone / date_default_timezone_set()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆