php - date_default_timezone_set不起作用,但ini_set'date.timezone'。为什么? [英] php - date_default_timezone_set not working, but ini_set 'date.timezone' does. Why?

查看:805
本文介绍了php - date_default_timezone_set不起作用,但ini_set'date.timezone'。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题所示,任何人都可以解释为什么代码

  ini_set('date.timezone','Europe / Athens '); 

工作,但

 code> date_default_timezone_set('Europe / Athens'); 

不?



我在看为了一个解决方案来转换时间戳,我可以在网上找到的是使用 date_default_timezone_set 。但转换总是有1小时的差异。



然后我发现这个主题 strftime()功能显示不正确的时间这是使用init_set代码(之后我有RTFM和发现它已经在文档中提到)。我尝试了它,它的工作。



但是我没有找到一个答案为什么 date_default_timezone_set 不工作。 / p>

有人可以解释吗?

解决方案

你必须使用旧的PHP的版本。

  date_default_timezone_set适用于PHP 5.1.2及更高版本。 

尝试 php -v 并检查您的PHP版本。


As the title says, can anybody explain why the code

ini_set( 'date.timezone', 'Europe/Athens' );

works but

date_default_timezone_set( 'Europe/Athens' );

does not?

I was looking for a solution to convert a timestamp and all I could find on the web was to use date_default_timezone_set. But the conversion had always 1 hour difference.

Then I found this topic "strftime() function showing incorrect time" which is using the init_set code (and afterwards I've RTFM and found out that it's already mentioned in the documentation). I tried it and it worked.

But I haven't found an answer why date_default_timezone_set is not working.

Can anybody explain please?

解决方案

You must be using an old version of PHP.

date_default_timezone_set is for PHP 5.1.2 and above.

Try php -v and check your PHP version.

这篇关于php - date_default_timezone_set不起作用,但ini_set'date.timezone'。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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