【问题标题】:PHP warning when I use the date function [duplicate]我使用日期函数时的PHP警告[重复]
【发布时间】:2014-07-20 12:55:03
【问题描述】:

我的 PHP 代码中有这一行,用于根据日期、成员 ID 和评论生成 guid:

$md5c = md5($member_id.$comment.$topic_id.$plan_id.date("Y-m-d") );

最近它开始发出这样的警告信息:

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 the timezone 'UTC' for now, but please set date.timezone to select your timezone.

有谁知道如何更改该代码以便不生成此警告?

谢谢!

【问题讨论】:

  • 打开您的PHP.ini 并为@Saman Gholami 的答案中提到的date.timezone 设置写入一个新值

标签: php


【解决方案1】:

您可能需要将时区放在 php.ini 文件的配置行中。你的 php.ini 文件中应该有这样的块:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York

如果没有,请添加它(将时区替换为您的时区)。配置好后,一定要重启httpd(service httpd restart)。

这里是list of supported timezones。 参考是here。

【讨论】:

  • 我的 php.ini 文件中已经有这样的设置: date.timezone = "US/Eastern" ....这还不够吗?
  • 我需要像现在这样的引号吗?在您的示例中没有引号。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-08
  • 1970-01-01
  • 1970-01-01
  • 2012-10-05
  • 1970-01-01
  • 2012-12-14
  • 2012-05-06
相关资源
最近更新 更多