note 58133 added to function.date

From: Date: Tue, 25 Oct 2005 10:24:26 +0000
Subject: note 58133 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-97560@lists.php.net to get a copy of this message
Using 'B' for the Swatch Internet Time (i.Beats) can still lead to misunderstandings, because the date given in the resulting string is the local date, not the date of the BMT (Biel Mean Time / UTC+0100) after which the i.Beats are counted. So while @000 is equal all around the globe, October 25th 2005 @000 in Chicago is really October 24th, 06:00 PM local time. Otherwise, if you use date('d M Y @B') in Chicago on that day at 6pm, it will return "24 Oct 2005 @000" although it should be "25 Oct 2005 @000". So it may happen that you miss an appointment by 24 hours (or 1000 Beats ;-) Here's a way to return the Internet Time with correct date: <?php $curtime = time(); $utcdiff = date('Z', $curtime); // get difference to UTC in seconds $bmttime = $curtime - $utcdiff + 3600; // BMT = UTC+0100 $ssm = date('H', $bmttime)*3600 + date('i', $bmttime)*60 + date('s', $bmttime); // seconds since midnight (BMT) $ibeats = $ssm/86.4; // 86400 seconds = 1000 beats, so 1 beat = 86.4 seconds echo 'i.Beats : ' . date('D, d M Y', $bmttime) . ' @' . $ibeats; ?> Note: If you would try date('D, d M Y @B', $bmttime), the resulting beats would be wrong because the timezone used for calculation of the beats within the date() function is still your local one but the timestamp is UTC+0100. Another working way would be: <?php $curtime = time(); $utcdiff = date('Z', $curtime); // get difference to UTC in seconds $bmttime = $curtime - $utcdiff + 3600; // BMT = UTC+0100 echo 'i.Beats : ' . date('D, d M Y', $bmttime) . ' @' . date('B', $curtime); ?> But this way there are no floating-point beats possible, which may be handy sometimes. ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58133 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58133&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58133&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58133&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58133&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58133&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58133&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58133&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58133&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97560) next »