关于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即可!

相关文章

smarty缓存用法分析

本文详细分析了smarty缓存的用法。分享给大家供大家参考。具体分析如下: 一开始以为smarty只是用来做一些掩饰php代码功能,但是后来才知道还有模板缓存这个强大的功能。 什么是模板...

php实现html标签闭合检测与修复方法

本文实例讲述了php实现html标签闭合检测与修复方法。分享给大家供大家参考。具体如下: html标签闭合检测与修复,说的有点大 , 并没有考虑的很完整,没有使用正则表达式, 适用于ht...

判断PHP数组是否为空的代码

PHP判断数组为空首选方法:count($arr),size($arr); 复制代码 代码如下: $arr= array(""); echo count($arr); echo...

PHP中调用ASP.NET的WebService的代码

其中有个web method像这样的: 复制代码 代码如下: [WebMethod] public string HelloWorld() { return "Hello World";...

php版淘宝网查询商品接口代码示例

本文来给大家介绍一个php版淘宝网查询商品接口代码的例子,下面要改成你的信息的在代码后面都有说明了,同时sdk包我们也要官方下载。 下载SDK后直接引用包,并创建如下的类,并运行之,即完...