我在格式化从 MySQL 数据库收到的日期时遇到问题。我不断收到此错误:
Notice: A non well formed numeric value encountered in C:\xampp\htdocs\index.php on line 23
这是我的代码:
$news_query = $database->query("SELECT * FROM " . DB_NEWS . " ORDER BY 'date'");
while($news_data = mysql_fetch_array($news_query,MYSQL_ASSOC)){
$date = date("M d, Y - g:i:s A", $news_data['date']);
echo "
<DIV class = 'news_post'>
<DIV class = 'news_title'>" . $news_data['title'] . "</DIV>
<DIV class = 'news_info'>Posted on " . $date . " By " . $news_data["author"] . "</DIV>
<DIV class = 'entry'>" . $news_data['entry'] . "</DIV>
</DIV>";
}
我已经阅读了有关时间戳和日期函数的 PHP 手册,但我似乎无法弄清楚我的问题是什么。
最佳答案
您在 MySQL 中使用日期时间格式吗?
试试这个:
<?php
date("M d, Y - g:i:s A", strtotime( $news_data['date'] ) );
?>
关于php - PHP 中的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9854315/