关于php程序报date()警告的处理(date_default_timezone_set)

yipeiwu_com5年前PHP代码库

在写php程序中有时会出现这样的警告:

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 methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in D:\PHPWEB ews\file.php on line 17 。

这是因为PHP所取的时间是格林威治标准时间,所以和你当地的时间会有出入格林威治标准时间和北京时间大概差8个小时左右,我们可以按照下面的方法解决:

1、在页头使用date_default_timezone_set()设置我的默认时区为北京时间,即 <?php date_default_timezone_set("PRC"); ?>就可以了。

2、在php.ini中设置date.timezone的值为PRC,设置好以后的为:date.timezone=PRC或者date.timezone = Asia/Shanghai,同时取消这一行代码的注释,即去掉前面的分号就可以了。

然后重启apache即可!

相关文章

php获取当前时间的毫秒数的方法

php本身没有提供返回毫秒数的函数,但提供了一个microtime()函数,该函数返回一个array,包含两个元素,一个是秒数,一个是小数表示的毫秒数,借助此函数,可以很容易定义一个返回...

PHP执行速率优化技巧小结

1.在可以用file_get_contents替代file、fopen、feof、fgets等系列方法的情况下,尽量用file_get_contents,因为他的效率高得多!但是要注意f...

php文件上传表单摘自drupal的代码

drupal文件上传表单的例子 复制代码 代码如下: function upload_form() { $form = array(); // If this #attribute is...

刷新PHP缓冲区为你的站点加速

在当前 PHP 版本的默认配置下,“输出缓冲(Output Buffering)”是被打开的。旧版本则不是这样,在旧版本的 PHP 中,字符串在每次被输出的时候(通过 echo 或 pr...

php合并数组array_merge函数运算符加号与的区别

array_merge在参考手册中的说明如下: array_merge() 将两个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。 如果输入的数组中有...