Time Zone Conversion PHP [modified]
-
I am having a problem understand how to work with time zones in PHP I am trying to create a function where i can pass it a time zone and it will calculate the time in that time zone. i have read countless forms about this and still have hit a brick wall. If any one has any links or information they can share on how to do this i would be forever grateful. All i need to do is find out what the current time is in eastern pacific and central time zones.
-
I am having a problem understand how to work with time zones in PHP I am trying to create a function where i can pass it a time zone and it will calculate the time in that time zone. i have read countless forms about this and still have hit a brick wall. If any one has any links or information they can share on how to do this i would be forever grateful. All i need to do is find out what the current time is in eastern pacific and central time zones.
This is a cut'n'paste from the DateTime::setTimezone section of the PHP manual:
Example #1 Setting and getting DateTimeZone objects
<?php
date_default_timezone_set('Europe/London');$datetime = new DateTime('2008-08-03 12:35:23');
echo $datetime->getTimezone()->getName() . "\n";$datetime = new DateTime('2008-08-03 12:35:23');
$la_time = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($la_time);
echo $datetime->getTimezone()->getName();
?>
The above example will output:Europe/London
America/Los_AngelesElsewhere in the date/time chapter there are heaps of examples of various date/time manipulations. What I think you want to do is something like this:
$datetime = new DateTime(something);
$datetime->setTimezone(xxx);
$timexxx = $datetime->format($formatstring);
$datetime->setTimezone(yyy);
$timeyyy = $datetime->format($formatstring);[edit]fixed html quoting[/edit]
Software rusts. Simon Stephenson, ca 1994.
modified on Thursday, August 5, 2010 8:47 PM
-
I am having a problem understand how to work with time zones in PHP I am trying to create a function where i can pass it a time zone and it will calculate the time in that time zone. i have read countless forms about this and still have hit a brick wall. If any one has any links or information they can share on how to do this i would be forever grateful. All i need to do is find out what the current time is in eastern pacific and central time zones.