note 110377 deleted from function.microtime by danbrown

From: Date: Wed, 17 Oct 2012 21:19:07 +0000
Subject: note 110377 deleted from function.microtime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191370@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- 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.

« previous php.notes (#191370) next »