note 86950 added to function.date-default-timezone-set

From: Date: Wed, 12 Nov 2008 04:29:01 +0000
Subject: note 86950 added to function.date-default-timezone-set
Groups: php.notes 
Request: Send a blank email to php-notes+get-146409@lists.php.net to get a copy of this message
While it's easy to change timezones based on names or abbreviations, I haven't found any straightforward way of doing so using an offset integer. This situation comes up if you're using AJAX to get information about a user's timezone; javascript's getTimezoneOffset() method just sends you an offset number. So, here's my clunky solution: an adaptation of chris' function at http://us.php.net/manual/en/function.timezone-name-from-abbr.php. <?php function set_tz_by_offset($offset) { $abbrarray = timezone_abbreviations_list(); foreach ($abbrarray as $abbr) { foreach ($abbr as $city) { if ($city['offset'] == $offset) { // remember to multiply $offset by -1 if you're getting it from js date_default_timezone_set($city['timezone_id']); return true; } } } date_default_timezone_set("ust"); return false; } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 63.164.30.49 ---- Manual Page -- http://www.php.net/manual/en/function.date-default-timezone-set.php Edit -- https://master.php.net/note/edit/86950 Del: integrated -- https://master.php.net/note/delete/86950/integrated Del: useless -- https://master.php.net/note/delete/86950/useless Del: bad code -- https://master.php.net/note/delete/86950/bad+code Del: spam -- https://master.php.net/note/delete/86950/spam Del: non-english -- https://master.php.net/note/delete/86950/non-english Del: in docs -- https://master.php.net/note/delete/86950/in+docs Del: other reasons-- https://master.php.net/note/delete/86950 Reject -- https://master.php.net/note/reject/86950 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146409) next »