Question Detail

How to change a Date which is from another timezone to my timezone in php ?

2 years ago Views 798 Visit Post Reply

I want to change a date which is from another timezone to my current timezone. like I have a UTC timezone DateTime I want to change it to GMT timezone. 


I have tried this. 
$the_date = strtotime("2010-01-19 00:00:00");
echo(date_default_timezone_get() . "<br />");
echo(date("Y-d-mTG:i:sz",$the_date) . "<br />");
echo(date_default_timezone_set("UTC") . "<br />");
echo(date("Y-d-mTG:i:sz", $the_date) . "<br />");

Thread Reply

Lokesh Gupta

- 2 years ago

You will try this. Its working for me.

// old time zone

$utc = new DateTimeZone("UTC");

//Set new time zone

$india = new DateTimeZone("Asia/Kolkata"); //

$date = new DateTime( "2018-05-23 10:31:00", $utc );
$date->setTimezone( $india );
echo $date->format('Y-m-d H:i:s');