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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.