php - Convert Timestamp to Timezones -
i have timestamp user enters in gmt.
i display timestamp in gmt, cet, pst, est.
thanks post below have made, works perfectly!
public static function make_timezone_list($timestamp, $output='y-m-d h:i:s p') { $return = array(); $date = new datetime(date("y-m-d h:i:s", $timestamp)); $timezones = array( 'gmt' => 'gmt', 'cet' => 'cet', 'est' => 'est', 'pst' => 'pst' ); foreach ($timezones $timezone => $code) { $date->settimezone(new datetimezone($code)); $return[$timezone] = $date->format($output); } return $return; }
you use php 5's datetime
class. allows fine-grained control on timezone settings , output. remixed manual:
$timestamp = .......; $date = new datetime("@".$timestamp); // snap utc because of // "@timezone" syntax echo $date->format('y-m-d h:i:sp') . "<br>"; // utc time $date->settimezone(new datetimezone('pacific/chatham')); echo $date->format('y-m-d h:i:sp') . "<br>"; // pacific time $date->settimezone(new datetimezone('europe/berlin')); echo $date->format('y-m-d h:i:sp') . "<br>"; // berlin time
Comments
Post a Comment