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

From: Date: Mon, 11 Oct 2010 08:35:20 +0000
Subject: note 100357 added to function.date-default-timezone-set
Groups: php.notes 
Request: Send a blank email to php-notes+get-173125@lists.php.net to get a copy of this message
Most of the scripts here depend on PHP identifying the correct zone when one is not set, but that does not always happen. For example PHP 5.3.3 gives a 'UTC' result for a detected '8.0/no DST'. Not much help. So for those of us who for very good reasons really cannot set time zones in scripts of in .ini files, here is a function for use in a Windows environment that sets the default time zone to the OS time zone and returns the detected and set texts. function date_system_timezone_set(){ $shell = new COM("WScript.Shell") or die("Requires Windows Scripting Host"); $time_bias = -($shell->RegRead( "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control \\TimeZoneInformation\\Bias"))/60; $ab = -($shell->RegRead( "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control \\TimeZoneInformation\\ActiveTimeBias"))/60; $sc = $shell->RegRead( "HKEY_USERS\\.DEFAULT\\Control Panel\\International\\sCountry"); foreach(timezone_abbreviations_list() as $tza) foreach($tza as $entry){ $country = strtok($entry['timezone_id'],'/'); $locale = strtok('|'); if($country==$sc && $ab==($entry['offset']/60/60) && ($ds = $time_bias!=$ab)==$entry['dst']){ date_default_timezone_set($timezone_identifier = $country."/".$locale); return sprintf('%.1f',$ab)."/".($ds?'':'no ').'DST'." ".$timezone_identifier; } } return false; } ---- Server IP: 64.71.164.2 Probable Submitter: 203.20.16.101 ---- Manual Page -- http://www.php.net/manual/en/function.date-default-timezone-set.php Edit -- https://master.php.net/note/edit/100357 Del: integrated -- https://master.php.net/note/delete/100357/integrated Del: useless -- https://master.php.net/note/delete/100357/useless Del: bad code -- https://master.php.net/note/delete/100357/bad+code Del: spam -- https://master.php.net/note/delete/100357/spam Del: non-english -- https://master.php.net/note/delete/100357/non-english Del: in docs -- https://master.php.net/note/delete/100357/in+docs Del: other reasons-- https://master.php.net/note/delete/100357 Reject -- https://master.php.net/note/reject/100357 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173125) next »