note 84640 added to function.date-create
| From: | jioolk at gmail dot com | Date: | Wed, 23 Jul 2008 11:18:58 +0000 |
| Subject: | note 84640 added to function.date-create | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142589@lists.php.net to get a copy of this message | ||
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 :
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)
----
Server IP: 147.32.160.17
Probable Submitter: 212.111.12.164
----
Manual Page -- http://www.php.net/manual/en/function.date-create.php
Edit -- https://master.php.net/note/edit/84640
Del: integrated -- https://master.php.net/note/delete/84640/integrated
Del: useless -- https://master.php.net/note/delete/84640/useless
Del: bad code -- https://master.php.net/note/delete/84640/bad+code
Del: spam -- https://master.php.net/note/delete/84640/spam
Del: non-english -- https://master.php.net/note/delete/84640/non-english
Del: in docs -- https://master.php.net/note/delete/84640/in+docs
Del: other reasons-- https://master.php.net/note/delete/84640
Reject -- https://master.php.net/note/reject/84640
Search -- https://master.php.net/manage/user-notes.php