-3

Please help in converting 1st date format into 2nd date format.

This is just example:

2016-08-18 22:09:53

to

2016-08-18T09:20:00+08:00

I am using

$the_date = strtotime("016-08-18 22:09:53");
echo(date_default_timezone_get() . "<br />");
echo(date("Y-d-mTG:i:sz",$the_date) . "<br />");

OUTPUT

Asia/calcutta

2016-18-08IST22:09:53230

but this time format is still not similar to 2016-08-18T09:20:00+08:00

sanjeev
  • 13
  • 7
  • echo(date("Y-m-d\TH:i:sP",$the_date) . "
    ");
    – sanjeev Aug 21 '16 at 17:54
  • Use format `c` while formating with `date()` function, which will return `ISO 8601 date (added in PHP 5)`; example `2004-02-12T15:19:21+00:00`. And change timezone if you wish to get `+08:00` offset. – Glavić Aug 21 '16 at 17:55
  • @sanjeev I am trying to understand, which is the correlation between the time of the first date and the time of the second date you provided in your example – G.Margaritis Aug 21 '16 at 18:00

2 Answers2

1
date_default_timezone_set('UTC');
$the_date = strtotime("016-08-18 22:09:53");
echo date(DATE_ATOM, $the_date);
Achyut Kr Deka
  • 739
  • 1
  • 8
  • 18
0

use this format "Y-m-d\TH:i:sP"

sanjeev
  • 13
  • 7