note 116914 added to function.date

From: Date: Fri, 20 Mar 2015 16:45:38 +0000
Subject: note 116914 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-201995@lists.php.net to get a copy of this message
If you have a problem with the different time zone, this is the solution for that. <?php // first line of PHP $defaultTimeZone='UTC'; if(date_default_timezone_get()!=$defaultTimeZone)) date_default_timezone_set($defaultTimeZone); // somewhere in the code function _date($format="r", $timestamp=false, $timezone=false) { $userTimezone = new DateTimeZone(!empty($timezone) ? $timezone : 'GMT'); $gmtTimezone = new DateTimeZone('GMT'); $myDateTime = new DateTime(($timestamp!=false?date("r",(int)$timestamp):date("r")), $gmtTimezone); $offset = $userTimezone->getOffset($myDateTime); return date($format, ($timestamp!=false?(int)$timestamp:$myDateTime->format('U')) + $offset); } /* Example */ echo 'System Date/Time: '.date("Y-m-d | h:i:sa").'<br>'; echo 'New York Date/Time: '._date("Y-m-d | h:i:sa", false, 'America/New_York').'<br>'; echo 'Belgrade Date/Time: '._date("Y-m-d | h:i:sa", false, 'Europe/Belgrade').'<br>'; echo 'Belgrade Date/Time: '._date("Y-m-d | h:i:sa", 514640700, 'Europe/Belgrade').'<br>'; ?> This is the best and fastest solution for this problem. Working almost identical to date() function only as a supplement has the time zone option. ---- Server IP: 72.52.91.14 Probable Submitter: 178.221.177.44 ---- Manual Page -- http://php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/116914 Del: integrated -- https://master.php.net/note/delete/116914/integrated Del: useless -- https://master.php.net/note/delete/116914/useless Del: bad code -- https://master.php.net/note/delete/116914/bad+code Del: spam -- https://master.php.net/note/delete/116914/spam Del: non-english -- https://master.php.net/note/delete/116914/non-english Del: in docs -- https://master.php.net/note/delete/116914/in+docs Del: other reasons-- https://master.php.net/note/delete/116914 Reject -- https://master.php.net/note/reject/116914 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201995) next »