Question

I need to convert a date to GMT, and I was considering relying on this script (derived from what found in date_default_timezone_set documentation's comments (http://us.php.net/manual/en/function.date-default-timezone-set.php):

$userDate = "2012-12-05 12:13:41";
$userTimezone = "America/New_York";
$dateResult = convertDate($userDate, $userTimezone);

function convertDate($dateOrigin, $timezoneOrigin) {
    $date = new DateTime($dateOrigin, new DateTimeZone($timezoneOrigin)); 
    date_default_timezone_set('Europe/London'); 
    return date("Y-m-d h:i:s", $date->format('U'));
}

But I was wondering, the above code would consider daylight time saving changes? I mean, given the user's timezone and date, when converting to another timezone, does the above code considers the differences that may occur because of DTS?

Was it helpful?

Solution

After some testing the answer is no. The conversion using the above code does not consider DTS changes. So I guess that code is pretty much useless.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top