With below javascript code I get timestamp
<script>
Date().getTime()
</script>
Which results in 1454497242551
how can I get the same kinda timestamp via php
With below javascript code I get timestamp
<script>
Date().getTime()
</script>
Which results in 1454497242551
how can I get the same kinda timestamp via php
PHP and large integers seem to cause issues but perhaps you could try:
quick and easy way
-----------------
echo sprintf('%013.0f', microtime(1)*1000 );
alt version, but no more accurate
---------------------------------
$pieces = explode( " ", microtime() );
$ctstmp = bcadd( ( $pieces[0]*1000 ), bcmul( $pieces[1], 1000 ) );
echo $ctstmp;
In Javascript
var ts=new Date().getTime();
results:
--------
Javascript: 1454592264750
PHP ( sprintf ): 1454592264020
PHP ( alt ): 1454592264020
It is correct to multiply by 1000 because microtime(true) returns the Unix timestamp in seconds as a float and the javascript new Date().getTime()
returns the number of milliseconds since the DateTime epoch ( where they both use the epoch time of 1970/01/01 )
Ok, there is a difference between the PHP and the Javascript - that could be due to rendering on the page.