1

While using google api for feed, I get blog post's creation time in format - 2015-04-11T06:33:00.001-07:00 which is datestamp for another timezone. I want to convert datestamp to IST timezone (eg. 2015-04-12T09:51:00.001+05:30) with php. How do I do that?

In another question what all I could find is convert 2015-04-12T09:51:00.001 to another format, that's it. I am unable to convert it to mentioned format.

Glavić
  • 42,781
  • 13
  • 77
  • 107
  • possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Huey Apr 12 '15 at 07:08
  • @Huey - how's this possible duplicate when there's no mention of changine timezone that too in json date format there.? – Chahit Kumar Apr 12 '15 at 07:16

1 Answers1

2

This can be easily accomplished with DateTime:

$dt = new DateTime('2015-04-11T06:33:00.001-07:00');
$dt->setTimeZone(new DateTimeZone('Asia/Colombo'));
echo $dt->format('c');

demo

Glavić
  • 42,781
  • 13
  • 77
  • 107
  • woah.. that did in seconds... i was thinking of first getting timezone of date and then cast to this. But your solution help avoid that step and save time. thanks man. – Chahit Kumar Apr 12 '15 at 08:19
  • No need for that, DateTime knows how to deal with timezones, and a lot more :) [Here](http://php.net/manual/en/timezones.php) is the list of timezones, if you need it... – Glavić Apr 12 '15 at 08:23
  • was just on that link changing time zone from Asia/Colombo to Asia/Kolkata. – Chahit Kumar Apr 12 '15 at 08:25