-1

I am getting time with timezone from an API.

Example: 2019-06-25T08:01:32-05:00

How can I change to UTC time using PHP?

halfer
  • 19,471
  • 17
  • 87
  • 173
deepu sankar
  • 4,177
  • 3
  • 23
  • 36

1 Answers1

1

You can use the DateTime and DateTimeZone classes:

// this date format will consider the timezone '-05:00'
$dt = new DateTime('2019-06-25T08:01:32-05:00');
// then you convert it to utc
$dt->setTimeZone(new DateTimeZone('utc'));

echo $dt->format('Y-m-d H:i:s'); // will give you 2019-06-25 13:01:32

Manual DateTime: https://www.php.net/manual/en/class.datetime.php

Manual DateTimeZone: https://www.php.net/manual/en/class.datetimezone.php

olibiaz
  • 2,481
  • 4
  • 27
  • 31