note 96551 added to function.date-default-timezone-set
| From: | FrederickHathaway at osu1 dot php dot net | Date: | Thu, 04 Mar 2010 16:54:40 +0000 |
| Subject: | note 96551 added to function.date-default-timezone-set | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166664@lists.php.net to get a copy of this message | ||
It's really a hassle that there is no way to set the timezone offset. I attempted to use the
code that searched for the correct timezone name by offset from below. I found it didn't work
reliably since various cities may have different rules about time DST etc. My solution is to
actually search the array and do a test to insure the offset is what I expect it to be. It seems
very kludgey (if thats a word) but it works.
function setTimezoneByOffset($offset)
{
$testTimestamp = time();
date_default_timezone_set('UTC');
$testLocaltime = localtime($testTimestamp,true);
$testHour = $testLocaltime['tm_hour'];
$abbrarray = timezone_abbreviations_list();
foreach ($abbrarray as $abbr)
{
//echo $abbr."<br>";
foreach ($abbr as $city)
{
date_default_timezone_set($city['timezone_id']);
$testLocaltime = localtime($testTimestamp,true);
$hour = $testLocaltime['tm_hour'];
$testOffset = $hour - $testHour;
if($testOffset == $offset)
{
return true;
}
}
}
return false;
}
----
Server IP: 69.147.83.197
Probable Submitter: 67.130.24.230
----
Manual Page -- http://www.php.net/manual/en/function.date-default-timezone-set.php
Edit -- https://master.php.net/note/edit/96551
Del: integrated -- https://master.php.net/note/delete/96551/integrated
Del: useless -- https://master.php.net/note/delete/96551/useless
Del: bad code -- https://master.php.net/note/delete/96551/bad+code
Del: spam -- https://master.php.net/note/delete/96551/spam
Del: non-english -- https://master.php.net/note/delete/96551/non-english
Del: in docs -- https://master.php.net/note/delete/96551/in+docs
Del: other reasons-- https://master.php.net/note/delete/96551
Reject -- https://master.php.net/note/reject/96551
Search -- https://master.php.net/manage/user-notes.php