我创建了一个博客并对其进行了设置,以便在每篇博客文章上显示该文章的发布日期,我总是使用 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/