note 99006 added to function.date-default-timezone-set
| From: | DaneIracleous at osu1 dot php dot net | Date: | Wed, 21 Jul 2010 20:48:57 +0000 |
| Subject: | note 99006 added to function.date-default-timezone-set | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171026@lists.php.net to get a copy of this message | ||
Here is some useful code to set the default timezone to the user's local timezone.
<?php
function getLocalTimezone()
{
$iTime = time();
$arr = localtime($iTime);
$arr[5] += 1900;
$arr[4]++;
$iTztime = gmmktime($arr[2], $arr[1], $arr[0], $arr[4], $arr[3], $arr[5], $arr[8]);
$offset = doubleval(($iTztime-$iTime)/(60*60));
$zonelist =
array
(
'Kwajalein' => -12.00,
'Pacific/Midway' => -11.00,
'Pacific/Honolulu' => -10.00,
'America/Anchorage' => -9.00,
'America/Los_Angeles' => -8.00,
'America/Denver' => -7.00,
'America/Tegucigalpa' => -6.00,
'America/New_York' => -5.00,
'America/Caracas' => -4.30,
'America/Halifax' => -4.00,
'America/St_Johns' => -3.30,
'America/Argentina/Buenos_Aires' => -3.00,
'America/Sao_Paulo' => -3.00,
'Atlantic/South_Georgia' => -2.00,
'Atlantic/Azores' => -1.00,
'Europe/Dublin' => 0,
'Europe/Belgrade' => 1.00,
'Europe/Minsk' => 2.00,
'Asia/Kuwait' => 3.00,
'Asia/Tehran' => 3.30,
'Asia/Muscat' => 4.00,
'Asia/Yekaterinburg' => 5.00,
'Asia/Kolkata' => 5.30,
'Asia/Katmandu' => 5.45,
'Asia/Dhaka' => 6.00,
'Asia/Rangoon' => 6.30,
'Asia/Krasnoyarsk' => 7.00,
'Asia/Brunei' => 8.00,
'Asia/Seoul' => 9.00,
'Australia/Darwin' => 9.30,
'Australia/Canberra' => 10.00,
'Asia/Magadan' => 11.00,
'Pacific/Fiji' => 12.00,
'Pacific/Tongatapu' => 13.00
);
$index = array_keys($zonelist, $offset);
if(sizeof($index)!=1)
return false;
return $index[0];
}
date_default_timezone_set(getLocalTimezone());
?>
----
Server IP: 194.153.94.10
Probable Submitter: 173.11.92.50
----
Manual Page -- http://www.php.net/manual/en/function.date-default-timezone-set.php
Edit -- https://master.php.net/note/edit/99006
Del: integrated -- https://master.php.net/note/delete/99006/integrated
Del: useless -- https://master.php.net/note/delete/99006/useless
Del: bad code -- https://master.php.net/note/delete/99006/bad+code
Del: spam -- https://master.php.net/note/delete/99006/spam
Del: non-english -- https://master.php.net/note/delete/99006/non-english
Del: in docs -- https://master.php.net/note/delete/99006/in+docs
Del: other reasons-- https://master.php.net/note/delete/99006
Reject -- https://master.php.net/note/reject/99006
Search -- https://master.php.net/manage/user-notes.php