我想從數據庫中顯示日期和時間。時間問題在於它總是在改變它的值,並且與存儲在數據庫中的值不匹配。從MySQL數據庫顯示時間DATETIME
PHP代碼:
$query = mysql_query("SELECT `post_date`
FROM `private_section_posts`
WHERE `status` = 'show'");
while($post = mysql_fetch_array($query)) {
$postdayofweek = date("D", strtotime($post['post_date']));
$postday = date("d", strtotime($post['post_date']));
$postsuffix = date("S", strtotime($post['post_date']));
$postmonth = date("M", strtotime($post['post_date']));
$postyear = date("Y", strtotime($post['post_date']));
$posttime = date("g:ia", strtotime($post['post_date']));
echo $postdayofweek . ' ' . $postday . $postsuffix . ' ' . $postmonth . ' ' . $postyear .
' at ' . $time;
}
MYSQL POST_DATE:2014年1月28日04:00:00
輸出顯示:週二2014年1月28日在上午10:36
如果你存儲正確的時間,然後只是顯示它是一個子串時間字段。 –