Return local time from unix timestamp with timezone id in php

I have a drop-down list on a webpage that uses the timezone identifier as a value (however I can change it to keep GMT offset if this is the best choice). Currently, the user will save something like "America / Denver" as their time zone.

I need to convert the unix timestamp to the local time of the user to display in another part of the page. What is the best way to do this?

Would it be better to store the GMT offset in the database and use this to calculate the time? Can someone please point me in the right direction?

Thank!

+3
source share
1

- DateTime :

$t = new DateTime();
$t->setTimestamp( $time=time() );
$t->setTimeZone(new DateTimeZone("America/Denver"));
print $t->format(DateTime::RFC850);

, .

+5

All Articles