qadenza
qadenza

Reputation: 9293

how to change timezone of timestamp data

date_default_timezone_set('Europe/Belgrade');

Now, I'm getting data from a mysql table / a timestamp column named date

echo date("d. m. H:i", strtotime(htmlspecialchars($r['date'])))

Result is (for example) - 10. 09. 02:36

So, it works, but not in desired timezone. Displayed data are from server's location timezone.

How can I get the data recalculated according to my timezone?

Upvotes: 0

Views: 67

Answers (3)

Prashant Kyada
Prashant Kyada

Reputation: 23

Now check this code.

 date_default_timezone_set('America/New_York');
        $date = date('m/d/Y');
        $time = date('h:i'); 
        echo $date;
        echo $time;

Upvotes: 0

Vineet1982
Vineet1982

Reputation: 7918

Simply do this

 $timezone = "Asia/Calcutta";
 date_default_timezone_set($timezone);
 echo date("d. m. H:i", strtotime(htmlspecialchars($r['date'])))

This will provide you the correct result

Upvotes: 0

Dirgh
Dirgh

Reputation: 507

I faced nearly same problem and this is what i did

$mdate=new DateTime($date);
$mdate->setTimezone(new DateTimeZone('Australia/Melbourne'));
$newtime= $mdate->format("jS F, Y h:i:s a");

Hope it helps.

Upvotes: 2

Related Questions