note 96574 modified in datetimezone.gettransitions by aharvey

From: Date: Mon, 10 Sep 2012 01:18:45 +0000
Subject: note 96574 modified in datetimezone.gettransitions by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190597@lists.php.net to get a copy of this message
Getting a timezone&#39;s offset and other data at a specified point in time (now, for example) using the new PHP5.3 parameters:&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;$theTime = time(); # specific date/time we&#39;re checking, in epoch seconds.&#13;&#10;&#13;&#10;$tz = new DateTimeZone(&#39;America/Los_Angeles&#39;);&#13;&#10;$transition = $tz-&#62;getTransitions($theTime,$theTime);&#13;&#10;&#13;&#10;# only one array should be returned into $transition. Now get the data:&#13;&#10;$offset = $transition[0][&#39;offset&#39;];&#13;&#10;$abbr = $transition[0][&#39;abbr&#39;];&#13;&#10;?&#62;&#13;&#10;&#13;&#10;Before PHP5.3, you&#39;d have to loop through all of the Transitions up until the current point in time, which would be a very inefficient process. --was-- Getting a timezone's offset and other data at a specified point in time (now, for example) using the new PHP5.3 parameters: <?php $theTime = time(); # specific date/time we're checking, in epoch seconds. $tz = new DateTimeZone('America/Los_Angeles'); $transition = $tz-getTransitions($theTime,$theTime); # only one array should be returned into $transition. Now get the data: $offset = $transition[0]['offset']; $abbr = $transition[0]['abbr']; ?> Before PHP5.3, you'd have to loop through all of the Transitions up until the current point in time, which would be a very inefficient process. http://php.net/manual/en/datetimezone.gettransitions.php

« previous php.notes (#190597) next »