1

I have the following date string in the following format:

$received = "Tue, 15 Sep 2015 12:35:03 +0000 (UTC)";

I would like to convert this to the Europe/London timezone as the actual time is supposed to read 13:35:03

Any ideas how this can be done?

Thanks

Ahmed
  • 1,403
  • 4
  • 21
  • 44

3 Answers3

5

Set a new Timezone maybe you want to set this dynamically then set the new dateTime from database:

$received = "Tue, 15 Sep 2015 12:35:03 +0000 (UTC)";

$tz = new DateTimeZone('Europe/London');
$date = new DateTime($received);
$date->setTimezone($tz);
echo $date->format('H:i:s');

The output is:

13:35:03
aldrin27
  • 3,407
  • 3
  • 29
  • 43
1

The current/correct way to do this:

$received = "Tue, 15 Sep 2015 12:35:03 +0000 (UTC)";
$date = new DateTime($received);

echo $date->format('c'); // 2015-09-15T12:35:03+00:00

$date->setTimezone(new DateTimeZone('Europe/London'));

echo $date->format('c'); // 2015-09-15T13:35:03+01:00

You build the DateTime object from the string, then change the timezone.

samlev
  • 5,852
  • 1
  • 26
  • 38
0

hope this helps you need to create DateTime object then convert the time zone when you display after you change the time zone then it will display correct time.

$t = new DateTime($received);
date_timezone_set($t, timezone_open('Europe/London'));
echo date_format($t, 'Y-m-d H:i:sP');
Tom
  • 81
  • 5