I have created some simple function you can use to convert time to any timezone :
function convertTimeToLocal($datetime,$timezone='Europe/Dublin') {
$given = new DateTime($datetime, new DateTimeZone("UTC"));
$given->setTimezone(new DateTimeZone($timezone));
$output = $given->format("Y-m-d"); //can change as per your requirement
return $output;
}
If you have access to PHP 5.3, the intl extension is very nice for doing things like this.
Here's an example from the manual:
$fmt = new IntlDateFormatter( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/Los_Angeles',IntlDateFormatter::GREGORIAN );
$fmt->format(0); //0 for current time/date
In your case, you can do:
$fmt = new IntlDateFormatter( "en_US" ,IntlDateFormatter::FULL, IntlDateFormatter::FULL,
'America/New_York');
$fmt->format($datetime); //where $datetime may be a DateTime object, an integer representing a Unix timestamp value (seconds since epoch, UTC) or an array in the format output by localtime().
As you can set a Timezone such as America/New_York
, this is much better than using a GMT or UTC offset, as this takes into account the day light savings periods as well.
Finaly, as the intl extension uses ICU data, which contains a lot of very useful features when it comes to creating your own date/time formats.
<?php
date_default_timezone_set('GMT-5');//Set New York timezone
$today = date("F j, Y")
?>
Set the default time zone first and get the date then, the date will be in the time zone you specify :
<?php
date_default_timezone_set('America/New_York');
$date= date('m-d-Y') ;
?>
http://php.net/manual/en/function.date-default-timezone-set.php
Source: Stackoverflow.com