如何将日期时间转换为"yyyy-MM-dd'T'HH:mm:ss. ssz "在PH


How to convert datetime to "yyyy-MM-dd'T'HH:mm:ss.SSSZ" in PHP

我需要发送数据日期时间到API。但我不转换为datetime格式相同下面

  "created_at": "2014-05-28T21: 38: 51.720986+11: 00",
  "date_of_birth": "1994-05-28T00: 00: 00+11: 00",

请帮帮我。

@DanielW注释,使用

为方便将来的读者,这里是工作格式:Y-m-d'TH:i:s.vO(时区中不带冒号)Y-m-d'TH:i:s.vP (时区中带冒号时区) .

使用

date('Y-m-d H:i:s.uZ', strtotime($created_at_input)); // yyyy-MM-dd'T'HH:mm:ss.SSSZ
date('c', strtotime($date_of_birth_input)); // yyyy-MM-ddTHH:mm:ss+00:00

,

echo date('Y-m-d'TH:i:s.vO', strtotime('2011-02-01 00:00:00')); // 2011-02-01T00:00:00.000+0000
echo date('Y-m-d'TH:i:s.vP', strtotime('2011-02-01 00:00:00')); // 2011-02-01T00:00:00.000+00:00
echo date('Y-m-d H:i:s.uP', strtotime('2011-02-01 00:00:00')); // 2011-02-01 00:00:00.000000+05:30
echo date(DATE_ATOM, strtotime('2011-02-01 00:00:00')); // 2011-02-01T00:00:00+05:30
echo date('c', strtotime('2011-02-01 00:00:00')); // 2011-02-01T00:00:00+05:30

<罢工>尝试

use date('c', strtotime($date_of_birth_input));

,

echo date('c', strtotime('2011-02-01 00:00:00')); //ouput: 2011-02-01T00:00:00+00:00 
> http://www.php.net/manual/en/function.date.php