note 84640 deleted from function.date-create by derick

From: Date: Tue, 05 Aug 2008 21:20:56 +0000
Subject: note 84640 deleted from function.date-create by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143184@lists.php.net to get a copy of this message
Note Submitter: jioolk at gmail dot com ---- In case you have on server, which you don't administer, version of php < 5.2 and need timezone conversion similar to DateTime, you can use this: <?php class DateUtils { public static function serverTime2ForeignTime($serverTimeStamp, $timezoneToTransferTo = "Europe/Prague") { // get local int representation of time $localTimestamp = strtotime($serverTimeStamp); // get far away places int representation of time $timezoneTimestamp = strtotime($serverTimeStamp . ' ' . $timezoneToTransferTo); // get difference of times $timezoneDifference = $timezoneTimestamp - $localTimestamp; // ammend local time to represent the same second as time in far away place return date("Y-m-d H:i:s", $localTimestamp - $timezoneDifference); } } //$timezoneToTransferTo should be in Olsen format. ?> It passed our set of unit tests generated using DateTime + DateTimeZone (we use just 76 zones, but don't have a reason to think it wont work for all)

« previous php.notes (#143184) next »