note 110377 added to function.microtime

From: Date: Tue, 16 Oct 2012 19:00:45 +0000
Subject: note 110377 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-191341@lists.php.net to get a copy of this message
I first struggled using date('Uu') because the u doesnt work there. Its a bit nonsense to take it into documentation when in fact it doesnt work. So i created a new function that gives the exact thing date('Uu') should give me: function get_unixusec($separate_usec = false){ list($usec, $sec) = explode(' ', microtime()); return date('U', $sec) . substr($usec, - 8 - $separate_usec, 6 + $separate_usec); } You can call it like: echo get_unixusec(); and you get 1350413363682803 or use echo get_unixusec(); and you get 1350413363.682854 The last one can be used for logfiles for easier reading. The first when using the timecode to run something after some microseconds. So calculating with it. Note that i only use the first 6 digits of the microseconds microtime is giving back because microseconds only have 6 digits. I dont know why it shows more. They are zero always anyway. Using all 8 digits would cause trouble when calculating because you would need to add 25000000 instead 250000 to add a quarter second. ---- Server IP: 69.147.83.199 Probable Submitter: 77.21.209.52 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit -- https://master.php.net/note/edit/110377 Del: integrated -- https://master.php.net/note/delete/110377/integrated Del: useless -- https://master.php.net/note/delete/110377/useless Del: bad code -- https://master.php.net/note/delete/110377/bad+code Del: spam -- https://master.php.net/note/delete/110377/spam Del: non-english -- https://master.php.net/note/delete/110377/non-english Del: in docs -- https://master.php.net/note/delete/110377/in+docs Del: other reasons-- https://master.php.net/note/delete/110377 Reject -- https://master.php.net/note/reject/110377 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191341) next »