尽管时区有效,但设置默认时区不起作用

2024-04-13php开发问题
1

本文介绍了尽管时区有效,但设置默认时区不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我只是在做 phpinfo() 时得到的

I'm geting when I just do phpinfo()

警告:phpinfo():依赖系统的时区设置是不安全的.您需要使用 date.timezone 设置或 date_default_timezone_set() 函数.如果您使用了这些方法中的任何一种,但仍然收到此警告,您很可能拼错了时区标识符.我们在第 8 行的/myadmin/i.php 中为EET/2.0/no DST"选择了Europe/Helsinki"

Warning: phpinfo(): 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 'Europe/Helsinki' for 'EET/2.0/no DST' instead in /myadmin/i.php on line 8

这里是 i.php:

<?php
//echo date_default_timezone_get();

date_default_timezone_set("Europe/Kiev");

//echo date("l");

phpinfo();
?>

如您所见,当我执行 date_default_timezone_set("Europe/Kiev") 时,我得到:

And as you can see, when I do date_default_timezone_set("Europe/Kiev") I get:

注意:date_default_timezone_set():时区 ID 'Europe/Kiev' 在/myadmin/i.php 第 4 行无效

Notice: date_default_timezone_set(): Timezone ID 'Europe/Kiev' is invalid in /myadmin/i.php on line 4

我确定我使用的是来自 here,我确实设置了:

I'm sure I'm using valid timezone string from here, and I did set :

date.timezone = 欧洲/基辅

date.timezone = Europe/Kiev

在 php.ini 文件中.

in php.ini file.

环境:CentOS 6,nginx/1.1.11,PHP 5.3.8 (fpm-fcgi)

Environment: CentOS 6 , nginx/1.1.11 , PHP 5.3.8 (fpm-fcgi)

我真的不明白这是怎么回事.谢谢.

I really can't understand what's a matter. Thank you.

推荐答案

感谢评论,我能够解决我的问题.我在控制台中做了什么:

Thanks to the comments, I was able to solve my problem. What I've done, in console:

#yum install php-pear

#pecl install timezonedb

需要c编译器:

configure: error: no acceptable C compiler found in $PATH

...所以我做了:

#yum install gcc

另外,如果您收到有关 make 命令的错误,只需运行

Also, if you get an error about the make command, simply run

#yum install make

最后,再试一次:

#pecl install timezonedb

...它显示在末尾:

You should add "extension=timezonedb.so" to php.ini

我将extension=timezonedb.so"添加到/etc/php.ini,并重启了php-fpm:

I added "extension=timezonedb.so" to /etc/php.ini, and restarted php-fpm:

#/etc/init.d/php-fpm restart

这篇关于尽管时区有效,但设置默认时区不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17