Page 1 of 1
time zone calculator
Posted: Thu Nov 14, 2013 1:39 pm
by Stella1229
I would like get some ideals on how to create a PHP program that would take a date/time in a specific timezone (say Pacific Time Zone), and spit out the equivalent date/time in selected timezones around the world.
For example,
Jan 1 2014 08:00 in Pacific (PST)-> Jan 1 2014 4pm in GMT.
Mar 10 2014 08:00 in Pacific (now in PDT) -> Mar 10 2014 3pm in GMT
April 1 2014 08:00 in Pacific (PDT) -> April 1 2014 4pm (now in BST)
the program needs to be smart enough to do the conversion as well as figure out the current timezones around the world for that date/time.
Any ideas or guidance would be much much appreciated

Re: time zone calculator
Posted: Thu Nov 14, 2013 11:04 pm
by requinix
PHP has that all built-in. The entirety of your application is essentially
Code: Select all
date_default_timezone_set("America/Los_Angeles");
$time = strtotime("Jan 1 2014 08:00"); // interpreted according to America/Los_Angeles
date_default_timezone_set("GMT");
echo date("M j Y H:i", $time); // outputted according to GMT
There are alternate methods of course, like the DateTime class, and you'd have to get your time and timezones from some input somewhere, but that's the gist of it.
Re: time zone calculator
Posted: Thu Nov 14, 2013 11:36 pm
by Eric!
Re: time zone calculator
Posted: Fri Nov 15, 2013 11:22 am
by Stella1229
Thanks for the information guys.. and please excuse my noob questions... How would I determine if UK is in GMT timezone or BST timezone for any given date/time the user enters?
Re: time zone calculator
Posted: Fri Nov 15, 2013 1:54 pm
by requinix
For converting
to? You'd then specify the timezone not as the actual timezone you're expecting but as the
location you want to convert to.
For example, you might want to convert to "London" time (which covers much, but not all, of the UK).
Code: Select all
date_default_timezone_set("America/Los_Angeles");
$time = strtotime("Jan 1 2014 08:00");
date_default_timezone_set("Europe/London");
echo date("M j Y H:i (T)\n", $time);
date_default_timezone_set("America/Los_Angeles");
$time = strtotime("Mar 10 2014 08:00");
date_default_timezone_set("Europe/London");
echo date("M j Y H:i (T)\n", $time);
date_default_timezone_set("America/Los_Angeles");
$time = strtotime("April 1 2014 08:00");
date_default_timezone_set("Europe/London");
echo date("M j Y H:i (T)\n", $time);
Code: Select all
Jan 1 2014 16:00 (GMT)
Mar 10 2014 15:00 (GMT)
Apr 1 2014 16:00 (BST)
Re: time zone calculator
Posted: Fri Nov 15, 2013 3:37 pm
by Stella1229
Bow to your greatness! Tremendous help!