pandu Posted July 21, 2010 Share Posted July 21, 2010 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 />"; } ?> Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 21, 2010 Share Posted July 21, 2010 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. Quote Link to comment Share on other sites More sharing options...
pandu Posted July 21, 2010 Author Share Posted July 21, 2010 That makes sense. Thanks for the clarification. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.