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

 2025-01-15  阅读 579  评论 8  点赞 238

摘要:在写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 y

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

关于php程序报date()警告的处理(date_default_timezone_set)-第1张-php-LS'Blog-保定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即可!


标签:phpphp教程

评论列表:

  •   danney
     发布于 2025-01-15 02:07:04回复该评论
  • 写的很不错,学到了!
  •   rick.li
     发布于 2025-01-15 14:07:04回复该评论
  • 又学到了新知识!
  •   hahaha1
     发布于 2025-01-15 20:07:04回复该评论
  • 哈哈哈不错!
  •   xiaoming22
     发布于 2025-01-16 02:07:04回复该评论
  • 谢谢分享!
  •   weihang233
     发布于 2025-01-16 08:07:04回复该评论
  • 不错,学习了!
  •   weihang
     发布于 2025-01-16 14:07:04回复该评论
  • 非常棒谢谢了!
显示更多评论

发表评论:

管理员

承接各种程序开发,外贸网站代运营,外贸网站建设等项目
  • 内容2471
  • 积分67616
  • 金币91666

Copyright © 2024 LS'Blog-保定PHP程序员老宋个人博客 Inc. 保留所有权利。 Powered by LS'blog 3.0.3

页面耗时0.0290秒, 内存占用2.04 MB, 访问数据库30次

冀ICP备19034377号