2

I need send data datetime to API. But I don't convert to format of datetime same below

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

Please help me. convert on PHP language

vankhoadesign
  • 53
  • 1
  • 2
  • 7

1 Answers1

13

@DanielW comments, use

For future readers, here is the working format: Y-m-d\TH:i:s.vO (without colon in timezone) and Y-m-d\TH:i:s.vP (with colon in timezone).

use

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

eg:

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

Try

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

eg:

echo date('c', strtotime('2011-02-01 00:00:00')); //ouput: 2011-02-01T00:00:00+00:00 

see http://www.php.net/manual/en/function.date.php

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70