【发布时间】:2013-05-15 22:55:04
【问题描述】:
我将如何转换以下内容以使其使用datetime class?:
array(
'post_date' => date('Y-m-d H:i:s', $date),
'post_date_gmt' => gmdate('Y-m-d H:i:s', $date),
);
例如,这部分很简单,但 gmdate 怎么样?
$oDate = new DateTime($date);
array(
'post_date' => $oDate->format('Y-m-d H:i:s'),
'post_date_gmt' => gmdate('Y-m-d H:i:s', $date),
);
【问题讨论】:
-
您只需将
DateTimeZone实例作为第二个参数传递给DateTime。$date = new DateTime($date, new DateTimeZone('GMT')); -
@OfirBaruch 太好了,我将关闭/删除这个问题
-
大声笑我必须投票才能结束我自己的问题
标签: php