note 109730 modified in function.microtime by danbrown
| From: | danbrown@php.net | 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: (Same as
javascript and
actionscript) ------------------------------- PHP ------------------------------- <?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(); }
--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