0

Currently I am using an API for flights search that shows flight details. In API response, few dates and GMTOffset is returned. I need to convert these to Pakistan Standard Time. API Response looks as following:

DepartureDateTime: 2018-11-10T14:20:00

ArrivalDateTime: 2018-11-11T07:10:00

DepartureTimeZone => "GMTOffset": -5

ArrivalTimeZone => "GMTOffset": 3

Kindly guide me how can I convert above date/time to Pakistan Standard Date/Time because I do not have an idea how these GMTOffset values will help me to get what I want.

Thank you!

Marvin Fischer
  • 2,552
  • 3
  • 23
  • 34
Ali Hamza
  • 17
  • 5
  • 4
    Please [edit] your question to show [the code you have so far](http://whathaveyoutried.com). Most of us here are happy to help you improve your craft, but are less happy acting as short-order unpaid programming staff. Show us your work so far as a [mcve], the result you were expecting and the results you got, and we'll help you figure it out. It may help to re-read [ask]. – Toby Speight Aug 08 '18 at 10:43
  • 1
    Possible duplicate of [Converting between timezones in PHP](https://stackoverflow.com/questions/5503135/converting-between-timezones-in-php) – CD001 Aug 08 '18 at 10:45

1 Answers1

0

You can use DateTime and DateTimeZone to set the UTC and your local timezone, this will automatically convert UTC to your local time:

$utc = "2018-11-10T14:20:00";
$dt = new DateTime($utc);
$tz = new DateTimeZone('Asia/Karachi'); // or whatever zone you're after

$dt->setTimezone($tz);
echo $dt->format('d-m-Y H:i:s');

Output: 10-11-2018 19:20:00

Tejashwi Kalp Taru
  • 2,994
  • 2
  • 20
  • 35