note 108467 added to function.date-default-timezone-set
| From: | boneytarker | Date: | Sat, 28 Apr 2012 07:49:54 +0000 |
| Subject: | note 108467 added to function.date-default-timezone-set | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187390@lists.php.net to get a copy of this message | ||
I used Dane Iracleous's snippet in a project of mine. and, found it no longer works in php
5.4.0 so heres my fix
<?php
function getLocalTimezone()
{
$zonelist = array(
-12 => 'Kwajalein',
-11 => 'Pacific/Midway',
-10 => 'Pacific/Honolulu',
-9 => 'America/Anchorage',
-8 => 'America/Los_Angeles',
-7 => 'America/Denver',
-6 => 'America/Tegucigalpa',
-5 => 'America/New_York',
-4.5 => 'America/Caracas',
-4 => 'America/Halifax',
-3.5 => 'America/St_Johns',
-3 => 'America/Argentina/Buenos_Aires',
-3 => 'America/Sao_Paulo',
-2 => 'Atlantic/South_Georgia',
-1 => 'Atlantic/Azores',
0 => 'Europe/London',
1 => 'Europe/Belgrade',
2 => 'Europe/Minsk',
3 => 'Asia/Kuwait',
3.5 => 'Asia/Tehran',
4 => 'Asia/Muscat',
5 => 'Asia/Yekaterinburg',
5.5 => 'Asia/Kolkata',
5.45 => 'Asia/Katmandu',
6 => 'Asia/Dhaka',
6.5 => 'Asia/Rangoon',
7 => 'Asia/Krasnoyarsk',
8 => 'Asia/Brunei',
9 => 'Asia/Seoul',
9.5 => 'Australia/Darwin',
10 => 'Australia/Canberra',
11 => 'Asia/Magadan',
12 => 'Pacific/Fiji',
13.00 => 'Pacific/Tongatapu',
);
$wmiObject = new COM("WinMgmts:\\\\.\\root\\cimv2");
$wmiObj = $wmiObject->ExecQuery("SELECT * FROM Win32_TimeZone");
foreach($wmiObj as $objItem)
{
$offset = $objItem->Bias;
}
return (array_key_exists($offset/60, $zonelist)) ? $zonelist[$offset] : "UTC" ;
}
date_default_timezone_set(getLocalTimezone());
?>
----
Server IP: 92.48.74.199
Probable Submitter: 90.207.50.10
----
Manual Page -- http://www.php.net/manual/en/function.date-default-timezone-set.php
Edit -- https://master.php.net/note/edit/108467
Del: integrated -- https://master.php.net/note/delete/108467/integrated
Del: useless -- https://master.php.net/note/delete/108467/useless
Del: bad code -- https://master.php.net/note/delete/108467/bad+code
Del: spam -- https://master.php.net/note/delete/108467/spam
Del: non-english -- https://master.php.net/note/delete/108467/non-english
Del: in docs -- https://master.php.net/note/delete/108467/in+docs
Del: other reasons-- https://master.php.net/note/delete/108467
Reject -- https://master.php.net/note/reject/108467
Search -- https://master.php.net/manage/user-notes.php