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

yipeiwu_com6年前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即可!

相关文章

学习thinkphp5.0验证类使用方法

通过一个实例,给大家讲解一下如果通过thinkphp5.0验证类的方法。 自定义验证类,需继承Validate类 比如在home模块新建validate文件夹,再新建Test.php验证...

简单概括PHP的字符串中单引号与双引号的区别

今天有个朋友问起,说下区别,顺便复习下。 单引号与双引号的不同: " "双引号里面的字段会经过编译器解释,然后再当作HTML代码输出。 ' '单引号里面的不进行解释,直接输出。...

phpmailer发送gmail邮件实例详解

复制代码 代码如下:<html><head><title>PHPMailer - SMTP (Gmail) basic test</title&...

php生成excel列名超过26列大于Z时的解决方法

本文实例讲述了php生成excel列名超过26列大于Z时的解决方法。分享给大家供大家参考。具体分析如下: 我们生成excel都会使用phpExcel类,这里就来给大家介绍在生成excel...

PHP实现支持GET,POST,Multipart/form-data的HTTP请求类

本文实例讲述了PHP实现支持GET,POST,Multipart/form-data的HTTP请求类及其应用,分享给大家供大家参考。具体如下: HttpRequest.class.php...