我将以下列格式获得时间作为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));
这是返回时间,但是时间会改变,我认为按照时区。我在DB中有记录,这些记录在convesrion之前插入,因此保留原始时间并进行比较。我怎么能这样转换它。我的意思是我需要在转换后将时间设为08:34:01
答案 0 :(得分:6)
$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类非常强大,几乎可以识别你抛出的任何格式。它非常适合操纵。