Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP equivalent of JavaScript getTime() [duplicate]

Suppose I'm running the following JavaScript getTime() function

<script language="JavaScript">
var $x = Math.round((new Date()).getTime()/1000);
</script>

What would the equivalent code in PHP look like?

like image 719
Mark Kennedy Avatar asked Sep 26 '13 00:09

Mark Kennedy


2 Answers

Try something like this:

echo number_format(microtime(true)*1000,0,'.','');

or because you are dividing by 1000, most probably you need this:

echo number_format(microtime(true),0,'.','');
like image 64
Salvador Dali Avatar answered Sep 28 '22 15:09

Salvador Dali


<?php
$x = time(); // seconds
$x = microtime(); // milliseconds
?>

Check out time() and microtime().

like image 29
Mr. B. Avatar answered Sep 28 '22 16:09

Mr. B.