note 107297 added to function.date-default-timezone-set
| From: | daneiracleous at gmail dot com | Date: | Sat, 28 Jan 2012 08:11:27 +0000 |
| Subject: | note 107297 added to function.date-default-timezone-set | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185776@lists.php.net to get a copy of this message | ||
If you want to set the default timezone to the user's local timezone, you have to combine PHP
and JavaScript. Here's how to do it:
<?php
session_start();
if(!isset($_SESSION['timezone']))
{
if(!isset($_REQUEST['offset']))
{
?>
<script>
var d = new Date()
var offset= -d.getTimezoneOffset()/60;
location.href = "<?php echo $_SERVER['PHP_SELF']; ?>?offset="+offset;
</script>
<?php
}
else
{
$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, $_REQUEST['offset']);
$_SESSION['timezone'] = $index[0];
}
}
date_default_timezone_set($_SESSION['timezone']);
//rest of your code goes here
?>
----
Server IP: 69.147.83.197
Probable Submitter: 68.185.77.28
----
Manual Page -- http://www.php.net/manual/en/function.date-default-timezone-set.php
Edit -- https://master.php.net/note/edit/107297
Del: integrated -- https://master.php.net/note/delete/107297/integrated
Del: useless -- https://master.php.net/note/delete/107297/useless
Del: bad code -- https://master.php.net/note/delete/107297/bad+code
Del: spam -- https://master.php.net/note/delete/107297/spam
Del: non-english -- https://master.php.net/note/delete/107297/non-english
Del: in docs -- https://master.php.net/note/delete/107297/in+docs
Del: other reasons-- https://master.php.net/note/delete/107297
Reject -- https://master.php.net/note/reject/107297
Search -- https://master.php.net/manage/user-notes.php