Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php新日期时间和gmdate_Php - Fatal编程技术网

php新日期时间和gmdate

php新日期时间和gmdate,php,Php,如何转换以下内容,使其使用 这部分很简单,但是日期呢 $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), ); 试试这个: $oDate->setTimezone(new DateTimeZone('GMT')); $oDate->form

如何转换以下内容,使其使用

这部分很简单,但是日期呢

$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),
);
试试这个:

$oDate->setTimezone(new DateTimeZone('GMT'));
$oDate->format('Y-m-d H:i:s');
试试这个:

$oDate->setTimezone(new DateTimeZone('GMT'));
$oDate->format('Y-m-d H:i:s');

在这种情况下,您需要两个对象,一个用于
GMT

$oDate = new DateTime($date);
$gmDate = new DateTime($date, new DateTimeZone('GMT'));

array(
   'post_date'     => $oDate->format('Y-m-d H:i:s'),
   'post_date_gmt' => $gmDate->format('Y-m-d H:i:s'),
);

在这种情况下,您需要两个对象,一个用于
GMT

$oDate = new DateTime($date);
$gmDate = new DateTime($date, new DateTimeZone('GMT'));

array(
   'post_date'     => $oDate->format('Y-m-d H:i:s'),
   'post_date_gmt' => $gmDate->format('Y-m-d H:i:s'),
);

只需将
DateTimeZone
实例作为第二个参数传递给
DateTime
<代码>$date=新日期时间($date,新日期时区('GMT'))要获得完整的解释,请看:@ofirbarch太好了,我将关闭/删除此问题。我必须投票才能关闭我自己的问题。您只需将
DateTimeZone
实例作为第二个参数传递到
DateTime
<代码>$date=新日期时间($date,新日期时区('GMT'))要获得完整的解释,请看:@ofirbarch太好了,我将关闭/删除此问题。我必须投票结束我自己的问题。不要忘记,这样做后,他希望回到标准时区。不要忘记,这样做后,他希望回到标准时区。