用PHP转换soap时间


convert soap time in PHP

我以以下格式获取时间作为API调用的响应。如何将其转换为Y-m-d H:I:s我使用了以下内容:

$time_other_format = '2013-10-29T08:34:01-0700';
$time = date("Y-m-d H:i:s",strtotime($time_other_format));

这是在返回时间,但时间发生了变化,我认为是根据时区。我在数据库中有记录,这些记录被插入到转换之前,因此保留了原始时间并进行比较。我怎么能这样转换呢。我的意思是,在转换后,我需要获得08:34:01的时间

$time_other_format = '2013-10-29T08:34:01-0700';
$dt = new DateTime($time_other_format);
echo $dt->format('Y-m-d H:i:s');

这将产生回声,

2013-10-29 08:34:01

PHP中的DateTime类非常强大,几乎可以识别任何你扔给它的格式。它非常适合操作。