php - stroftime 代码不在新的网络服务器上显示日期

标签 php mysql database mysqli strtotime

我创建了一个博客并对其进行了设置,以便在每篇博客文章上显示该文章的发布日期,我总是使用 stroftime() 来完成此操作,并从帖子所在的 MySQL 数据库获取记录日期已存储。

这一直有效,但我最近刚刚切换到新的网络主机,当我尝试使用原始代码时:

<?php $date = strtotime($post['post_date']);
        echo date('F jS, Y', $date); ?>

我收到一条错误消息:

Warning: strtotime(): 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. 

我只是不明白他们希望我用 date_default_timezone_set() 替换哪里。

最佳答案

Php 期望默认时区由应用程序而不是系统设置。因此,您必须在脚本开头或初始化的一部分调用 date_default_timezone_set 。然后您就可以安全地调用 strtotime。

 date_default_timezone_set('UTC')
 ...
 strtotime (...)

关于php - stroftime 代码不在新的网络服务器上显示日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34836307/

相关文章:

php - PDO 和 MySQL IN/NOT IN 查询的正确格式

database - 运行更新数据库导致错误 : "A file activation error occurred"

php - 我页面的渲染时间

php - 如何在 php 中定义自定义数字基数?

MySQL 在格式为 00/0000 时选择日期

mysql - 将所有日期时间字段转换为 UTC

ruby-on-rails - Rails 正在寻找/config/config/database.yml

sql - 为字典表找到正确的术语

php - 在模态中显示查询中的数据

mysql - 称为并行的存储过程按顺序返回结果