note 93154 added to function.date

From: Date: Tue, 25 Aug 2009 23:31:34 +0000
Subject: note 93154 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-159893@lists.php.net to get a copy of this message
This function behaves like date, but allows you to output the date in a given time zone locale. <?php function date_at_timezone($format, $locale, $timestamp=null){ if(is_null($timestamp)) $timestamp = time(); //Prepare to calculate the time zone offset $current = time(); //Switch to new time zone locale $tz = date_default_timezone_get(); date_default_timezone_set($locale); //Calculate the offset $offset = time() - $current; //Get the date in the new locale $output = date($format, $timestamp - $offset); //Restore the previous time zone date_default_timezone_set($tz); return $output; } //Examples $t = time(); print date("g:i A T", $t); //4:16 PM PDT print date_at_timezone("g:i A T", "America/New_York", $t); //7:16 PM EDT print date_at_timezone("g:i A T", "Pacific/Samoa", $t); //12:16 PM SST print date("g:i A T", $t); //4:16 PM PDT ?> ---- Server IP: 208.69.120.35 Probable Submitter: 74.212.230.74 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/93154 Del: integrated -- https://master.php.net/note/delete/93154/integrated Del: useless -- https://master.php.net/note/delete/93154/useless Del: bad code -- https://master.php.net/note/delete/93154/bad+code Del: spam -- https://master.php.net/note/delete/93154/spam Del: non-english -- https://master.php.net/note/delete/93154/non-english Del: in docs -- https://master.php.net/note/delete/93154/in+docs Del: other reasons-- https://master.php.net/note/delete/93154 Reject -- https://master.php.net/note/reject/93154 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159893) next »