Manivasagan
Manivasagan

Reputation: 212

How to Convert PST to GMT time in php?

I would like convert PST to GMT.

Ex:

PST : 22:00 need to convert in to GMT. I have to consider about DAY LIGHT SAVING TIME month also.

How can i do that?

Upvotes: 0

Views: 7155

Answers (2)

Jai Prakash
Jai Prakash

Reputation: 2779

I have to do similar for one my work and here it is how approached this:




     //date time in PST
        $t = 'Tue Feb 04 23:02:09 PST 2014';
        $dateTime = DateTime::createFromFormat("D M d H:i:s \P\S\T Y", $t, (new DateTimeZone('America/Los_Angeles')));
        var_dump($dateTime); // date time in PST format
        $dateTime->setTimezone(new DateTimeZone('UTC'));
        var_dump($dateTime); // date time in GMT format

Upvotes: 0

Glitch Desire
Glitch Desire

Reputation: 15023

Use PHP's built-in DateTime class...

Use DateTime objects which have this functionality built in:

$date = new DateTime('2013-08-06 15:00:00', new DateTimeZone('America/Los_Angeles'));
echo "The time in Los Angeles is " . $date->format('Y-m-d H:i:s') . "<br>";
$date->setTimezone(new DateTimeZone('Europe/London'));
echo "The time in London is " . $date->format('Y-m-d H:i:s') . "<br>";

(Example Code) (Full Documentation)

Upvotes: 7

Related Questions