php datetime not found,使用PHP警告DateTime

try{

$datetime1 = new DateTime("now");

$datetime2 = new DateTime("now");

$interval = $datetime1->diff($datetime2);

var_dump($interval);

}

catch(Exception $e) {

echo $e->getMessage();

}

我没有看到关于var_dump的任何结果,php的输出是:

DateTime::__construct(): It is not safe to rely on the system's timezone setting

s. You are *required* to use the date.timezone setting or the date_default_timez

one_set() function. In case you used any of those methods and you are still gett

ing this warning, you most likely misspelled the timezone identifier. We selecte

d 'Europe/Paris' for '1.0/no DST' instead

我正在使用php_cli 5.3.8

我能做什么?

谢谢

解决方法:

在PHP5.3中,有必要设置时区.

打开php.ini并找到设置date.timezone.取消注释并将其设置为某个值,例如

date.timezone = "Europe/Paris"

然后重启服务器.它应该照顾警告.

[编辑]

@greut提出的解决方案也可以正常工作.两者之间的区别在于php.ini设置是服务器范围的(将应用于现在和将来在服务器上运行的所有应用程序),而date_default_timezone_set()应用于当前仅执行的应用程序.

php.ini解决方案让您忘记运行的任何其他站点上的警告 – 但您需要访问php.ini.使用date_default_timezone_set()将覆盖php.ini中的设置,因此如果您愿意,可以同时使用这两种方法.

标签:php,date,datetime

来源: https://codeday.me/bug/20190711/1436643.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值