note 108467 deleted from function.date-default-timezone-set by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 16:56:38 +0000 |
| Subject: | note 108467 deleted from function.date-default-timezone-set by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187615@lists.php.net to get a copy of this message | ||
Note Submitter: boney tarker
----
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());
?>