-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,824
  • 17
  • 99
  • 186
deepu sankar
  • 4,335
  • 3
  • 26
  • 37

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,551
  • 4
  • 29
  • 31