PHP Warning: strftime(): It is not safe to rely on the system's timezone set

当运行一些程序时,在httpd日志中会有如下警告日志:

PHP Warning:  strftime(): 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 'Asia/Chongqing' for 'CST/8.0/no DST'。。。。。。。。。。。

  • 原因分析:
      这是因为PHP默认是以格林威治标准时间(UTC)为准进行时间转换,因为自己所处的当地时间与UTC会有出入,格林威治标准时间和北京时间有8个小时的时间差。因此我们必须为PHP指定一个时区,让php知道以哪个时区为准进行转换。

  • 解决办法:

  1. 在你的PHP程序头部使用date_default_timezone_set()设置我的默认时区为北京时间(PRC,中国的英文缩写),即  <?php     date_default_timezone_set("PRC");   ?>就可以了。这种方法使用时太复杂,必须在每个使用date的文件中添加相关函数,下面的方法更简单方便。

  2. 在php.ini中找到date.timezone行,支持前面的';'号(如果没有修改过的话应该是没有启动此选项的),并将它的值设置为PRC,设置好以后为:date.timezone="Asia/Shanghai"。

 
目前用第2 种方法解决了此问题

[服务器时区问题]PHP Warning: strftime(): It is not safe to rely on the system's timezone set的更多相关文章

  1. Warning: strftime(): It is not safe to rely on the system's timezone settings.

    当运行程序时,会出现如下警告: Warning: strftime(): It is not safe to rely on the system's timezone settings. You a ...

  2. php : Warning: strftime(): It is not safe to rely on the system's timezone settings.

    使用 Smarty 的时候出现这种警告: Warning: strftime(): It is not safe to rely on the system's timezone settings. ...

  3. PHP Warning: strftime(): It is not safe to rely on the system's timezone set

    当运行一些程序时,在httpd日志中会有如下警告日志: PHP Warning:  strftime(): It is not safe to rely on the system's timezon ...

  4. php时区设置 warning: strtotime(): It is not safe to rely on the system's timezone settings

    warning: strtotime(): It is not safe to rely on the system's timezone settings warning: strtotime(): ...

  5. PHP Warning: date(): It is not safe to rely on the system's timezone settings.

    OSSEC安装结束后运行,运行以下命令却抛错 cat /opt/ossec/logs/alerts/alerts.log 具体抛错内容: ** Alert 1468897672.2164786: ma ...

  6. Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use ...报错

    错误截图 Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* t ...

  7. 出现Warning: date(): It is not safe to rely on the system's timezone settings的解决办法

    在没有配置,尤其是新安装的PHP中使用date函数时,会报这个错误: Warning: date(): It is not safe to rely on the system's timezone ...

  8. PHP Warning: phpinfo(): It is not safe to rely on the system's timezone setting

    错误描述: PHP Warning:  phpinfo(): It is not safe to rely on the system's timezone settings. You are *re ...

  9. PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings.

    有三种解决办法: 1. php文件中设置时区 <?php date_default_timezone_set('Asia/Shanghai'); echo strtotime('2012-9-3 ...

随机推荐

  1. vSphere

    VMware vSphere集成容器(VIC)建立了一个在轻量级虚拟机内部署并管理容器的环境.全新的虚拟机环境提供了更高级别的硬件隔离度,灵活性以及可扩展性使得容器对开发人员以及企业应用具有如此大的吸 ...

  2. C语言计算两个日期间隔天数

    在网上看到了一个C语言计算日期间隔的方法,咋一看很高深,仔细看更高神,很巧妙. 先直接代码吧 #include <stdio.h> #include <stdlib.h> in ...

  3. contos7下安装redis&redis的主从复制的配置&redis 哨兵(sentinel)

    一.centos7下安装redis 1.解压 redis-5.0.5.tar.gz 压缩文件 解压命令为: .tar.gz -C redis 解压后进入 redis 工作目录,进入 redis-5.0 ...

  4. VUE 单选下拉框Select中动态加载 默认选中第一个

    <lable>分类情况</lable> <select v-model="content.tid"> <option v-for=&quo ...

  5. H5中的requestAnimationFrame

    这两天做一个公告展示轮播的动画,刚开始是用setinterval写的,后来发现做出来的动画效果有抖动的现象,动画不流畅,遂决定试试requestAnimationFrame,之前也只是耳闻,没有用过, ...

  6. Python——DataFrame转list(包含两种)

    import pandas as pd df = pd.DataFrame({'a':[1,3,5,7,4,5,6,4,7,8,9], 'b':[3,5,6,2,4,6,7,8,7,8,9]}) df ...

  7. Windows10关闭自动更新总结

    试过好多关闭windows自动更新的方法,但是在每次重启后发现C盘又塞了一堆更新包,强迫症的我必须要彻底关闭它! 1. services关闭 运行 services.msc ,找到Windows Up ...

  8. this绑定问题

    this是属性和方法“当前”(运行时)所在的对象.this是函数调用时发生的绑定,它的值只取决于调用位置(箭头函数除外). 函数调用的时候会产生一个执行上下文,this是对这个执行上下文的记录. ❌误 ...

  9. Razor传值到js

    1.Asp.net MVC 3 中Session与ViewBag传值到Js中 http://www.cnblogs.com/wintersun/archive/2012/06/04/2534975.h ...

  10. java常用函数

    if(null == list || list.size() ==0 ){ } list.isEmpty()和list.size()==0 没有区别 isEmpty()判断有没有元素而size()返回 ...