note 109730 modified in function.microtime by danbrown

From: Date: Fri, 31 Aug 2012 16:31:12 +0000
Subject: note 109730 modified in function.microtime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190380@lists.php.net to get a copy of this message
To return a timestamp as an integer with milliseconds:&#13;&#10;&#13;&#10;(Same as javascript and actionscript)&#13;&#10;&#13;&#10;-------------------------------&#13;&#10;PHP&#13;&#10;-------------------------------&#13;&#10;&#60;?php&#13;&#10;function getTimestamp(){&#13;&#10;&#9;$seconds = microtime(true); // false = int, true = float&#13;&#10;&#9;return round( ($seconds * 1000) );&#13;&#10;}&#13;&#10;&#13;&#10;print (&#34;&#60;pre&#62;&#34;);&#13;&#10;print (time().&#34;&#60;br&#62;&#34;);&#13;&#10;print (microtime(true).&#34;&#60;br&#62;&#34;);&#13;&#10;print (getTimestamp().&#34;&#60;br&#62;&#34;);&#13;&#10;print (&#34;&#60;/pre&#62;&#34;);&#13;&#10;?&#62;&#13;&#10;&#13;&#10;-------------------------------&#13;&#10;Javascript / Actionscript&#13;&#10;-------------------------------&#13;&#10;function getTimestamp(){&#13;&#10;&#9;var d = new Date();&#13;&#10;&#9;return Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()).valueOf();&#13;&#10;} --was-- To return a timestamp as an integer with milliseconds: (Same as javascript and actionscript) ------------------------------- PHP ------------------------------- function getTimestamp(){ $seconds = microtime(true); // false = int, true = float return round( ($seconds * 1000) ); } print ("<pre>"); print (time()."<br>"); print (microtime(true)."<br>"); print (getTimestamp()."<br>"); print ("</pre>"); ------------------------------- Javascript / Actionscript ------------------------------- function getTimestamp(){ var d = new Date(); return Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()).valueOf(); } http://php.net/manual/en/function.microtime.php

« previous php.notes (#190380) next »