PHP gets the timestamp in milliseconds, and php gets the timestamp in milliseconds. PHP obtains the timestamp in milliseconds. we know that the timestamp obtained by the time () function in php is measured in seconds. however, the timestamp obtained by the front-end JS, in milliseconds. in practice, PHP gets the timestamp in milliseconds and php gets the timestamp in milliseconds.
We know that the timestamp obtained by the time () function in PHP is measured in seconds.
However, the timestamp obtained by the front-end JS, in milliseconds. in practice, how can we unify the timestamps of JS and PHP, that is, how to use PHP to obtain the timestamp in milliseconds? See the following example:
// Function to obtain the timestamp in millisecondsfunction getMillisecond() { list($t1, $t2) = explode(' ', microtime()); return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);} // The above functions are from Baidu. I didn't quite understand them at the beginning.// Separate the description as follows:function getMillisecond_new(){// Use microtime () to obtain the microsecond timestamp. format (separated by spaces): 'Second's fractional part of the second's integer part', for example, '0. 69718900 1420440552'// Blow up the microsecond string explode and receive $ t1 = 0.69718900 $ t2 = 1420440552 list($t1, $t2) = explode(' ', microtime());// Convert it to a floating point number $t1=floatval($t1); $t2=floatval($t2);// Add x 1000 $total=( $t1+ $t2) * 1000;// Rounding $total=round($total,0);// Return results return $total;}Echo getMillisecond (), "PHP millisecond-getMillisecond ()
";Echo getMillisecond_new (). 'php millisecond-getMillisecond_new ()';/** Idea:* 1. use microtime () to obtain the microsecond timestamp. Format: 0.69718900 1420440552* 2. add the first and second parts x 1000, and round them to round ($ float, 0)* Second time () --> millisecond --> microsecond microtime (), which is 1000 hexadecimal between two* In this way, it can be consistent with the front-end JS timestamp.* JS: new Date (). getTime () obtains the timestamp in milliseconds. */?>> < code> > < code> > < code>>time</title</code>> <>> < code> >
< code>>