Jump to content

Trying to understand time conversion


pandu

Recommended Posts

Hello,

 

I am trying to understand how the time is changed from one time zone to the other in the code below.

All I see is that the time zone is changed and then the date function seems to "magically" update the time. But when I read the PHP manual for the date function, all the date function does is format output. So not sure how the change is happening. Would appreciate your insights. Thanks.

 

$time_zones = array("Asia/Tokyo","Asia/Hong_Kong","Asia/Dacca","Asia/Kuwait","Africa/Cairo","Europe/Paris","Europe/Madrid","Europe/London","America/New_York","America/Los_Angeles","America/Chicago");
if ($_GET["start_time"] != NULL){
$start_time_input = $_GET["start_time"];
$start_tz = $_GET["start_tz"];
$end_tz = $_GET["end_tz"];
date_default_timezone_set($start_tz);
$start_time = strtotime($start_time_input);
echo "<strong>";
echo date("h:i:sA",$start_time)."\n";
echo "</strong>";

echo "in $start_tz becomes ";
echo "<strong> ";
date_default_timezone_set($end_tz);
echo date("h:i:sA",$start_time)."\n";
echo "</strong>";
echo " in $end_tz.</p><hr />";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/208399-trying-to-understand-time-conversion/
Share on other sites

date_default_timezone_set() is a PHP function that sets the default timezone on the server. The function date() formats output and generates the date based on the default timezone of the server.

 

Essentially this means, if you set a different timezone using the date_default_timezone_set() function then the function date() will change to correspond with the new timezone.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.