从Wordpress帖子中获取时间(字段为存储在DATETIME中的post_date_gmt(,如何用PHP将该信息(例如2011-03-23 20:28:26(转换为实际的恶意日期?(如2011年3月23日星期四(
echo date('r', strtotime($datetime));
echo date('r', strtotime('2011-03-23 20:28:26'));
echo date('l, F jS, Y', strtotime('2011-03-23 20:28:26'));
有关更多格式选项,请参见date()
。
您可以使用strtotime
或DateTime
类。
// Using strtotime
$date = strtotime($row['post_date_gmt']);
// Using the DateTime class
$date = new DateTime($row['post_date_gmt']);
因为日期是GMT,而你的服务器很可能不是,所以最好也指定时区。下面是一个使用DateTimeZone
的示例。
$timezone = new DateTimeZone('UTC');
$date = new DateTime($row['post_date_gmt'], $timezone);
使用
date(formatString, yourDate)
或
gmdate(formatString, yourDate)
格式字符串示例:"D,D M Y H:i:s T">