ThomasReggi
ThomasReggi

Reputation: 59425

Convert datetime from GMT to regular time

I am trying to convert a string date to the correct timezone value, I would really appreciate any help. I've tried the following.

date_default_timezone_set('Etc/GMT-5');
date_default_timezone_set('GMT');

Source: 2011-12-28T00:14:33-05:00

GMT offset value: -05:00

String to time: 1325049273

format: "j M g:ia"

Showing as: 27 Dec 9:09pm

Should be showing as: 28 Dec 12:14am

Upvotes: 1

Views: 465

Answers (3)

ThomasReggi
ThomasReggi

Reputation: 59425

    $d = new DateTime('2011-12-28T00:14:33');
    echo $d->format('j M g:ia');

this worked =?

Upvotes: 0

Virendra
Virendra

Reputation: 2553

You don't need the date_default_timezone_set('GMT');

Try this

<?php
$source = '2011-12-28T00:14:33.000-05:00';
date_default_timezone_set('Etc/GMT-5');
$date = new DateTime($source);
echo $date->format('j M g:ha');
?>

Upvotes: 1

Kris
Kris

Reputation: 8868

$UTC = new DateTimeZone("UTC");
$newTZ = new DateTimeZone("Etc/GMT-5");
$date = new DateTime($your_source, $UTC );
$date->setTimezone( $newTZ );
echo $date->format('d-m-Y H:i:s');

Try this, it might work for you.

Upvotes: 1

Related Questions