您可以使用MySQL为您执行此操作,
$result = mysql_query("SELECT DATE_FORMAT(my_timestamp, '%M %d, %Y) AS my_timestamp FROM some_table WHERE id=42", $DB_CONN); $row = mysql_fetch_array($result); $formatted_date = $row['my_timestamp']; echo $formatted_date;
或者使用PHP,
$result = mysql_query("SELECT my_timestamp FROM some_table WHERE id=42", $DB_CONN); $row = mysql_fetch_array($result); $formatted_date = strftime('%B %d, %y', $row['my_timestamp']); echo $formatted_date;
我倾向于在SQL中进行日期格式化,就像Aron的回答一样.虽然PHP日期,我更喜欢使用的DateTime对象(PHP5 +)在日期:
$timestamp = new DateTime($row['my_timestamp']); echo $timestamp->format('F j, Y') . '
'; echo $timestamp->format('F j, Y g:ia');