PHP to get the number of milliseconds

Because the front-end processing functions need to write a timestamp, too much trouble, so we sometimes need to pass a few milliseconds to the front-end interfaces.

The following can be obtained by a number of milliseconds this function

. 1 ? < PHP
 2     function getMillisecond () {
 . 3         List ( $ microsecond , $ Time ) = the explode ( '', microtime, and ()); // '' is a middle space 
. 4         return ( a float ) sprintf ( '% .0f' , ( of floatval ( $ microsecond ) + of floatval ( $ Time )) * 1000 );
 . 5         }
 . 6 >?

   

Many people here do not know the list ($ microsecond, $ time) = explode ( '', microtime ());

Here we look at var_dump (explode ( '', microtime ()));

Returns the string (21) 0.46920200 1489743107 subtle former number, which is the number of milliseconds

Therefore, by (float) sprintf ( '%. 0f', (floatval ($ microsecond) + floatval ($ time)) * 1000) to obtain the number of milliseconds

Welcome to my blog to read more articles

 

Recommended reading:

2019 PHP programmers interview combat with answers

 

Guess you like

Origin www.cnblogs.com/993089249a/p/11701012.html