输出在我的PHP
文件中创建的日期时出现问题.
我一直在关注如何创建一个真正的基本CMS平台的教程,以帮助我理解一些基础知识,databases
并且PHP
在我尝试输出页面创建日期之前,一切都进展顺利.
这是我得到的错误
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): 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.' in
C:\MAMP\htdocs\basic-cms\page.php:22 Stack trace: #0 C:\MAMP\htdocs\basic-cms\page.php(22): DateTime->__construct('2016-02-17 10:3...') #1 {main} thrown in C:\MAMP\htdocs\basic-cms\page.php on line 22
Run Code Online (Sandbox Code Playgroud)
现在,当我删除我内部的第22行时,page.php
它会输出数据库中的完整日期,2016-02-17 10:38:05
但我正在尝试将其格式化以显示日期jS M, Y (17th Feb 2016)
.
这是我page.php
文件中的代码
if ( $page ) {
$page['created'] = new DateTime( $page['created'] );
if ( $page['updated'] ) {
$page['updated'] = new DateTime( $page['created'] );
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我show.php
显示的地方里面,我有这个代码来格式化日期.
Created on <?php echo $page['created']->format('jS M, Y'); ?>
Run Code Online (Sandbox Code Playgroud)
现在从我这里删除它show.php
并没有做任何事情,因为那不是包含错误的地方 - 但我想我会告诉你们我想要实现的目标.
就像我说这是一个非常基本的CMS网站,我正在通过关注YouTube上的教程来创建,我已经完全复制了他的代码并且他没有错误所以我确定它必须是一个错字我找不到.
Che*_*eta 10
这是因为在php配置中没有设置时区.
将以下代码行添加到php.ini文件的顶部
date.timezone = "US/Central"
Run Code Online (Sandbox Code Playgroud)
并重启Web服务器
要么
你可以通过php脚本设置它也可以使用以下功能:
date_default_timezone_set('America/Los_Angeles');
Run Code Online (Sandbox Code Playgroud)
别忘了重装/重启apache服务器
归档时间: |
|
查看次数: |
10419 次 |
最近记录: |