Get time and date in PHP we can use the DATE function, and if the milliseconds can be used but not specific, let me introduce some examples of PHP getting the current time milliseconds.
PHP itself does not provide a function to return milliseconds, but it provides a microtime () function that returns an array containing two elements, a number of seconds, and a fractional number of milliseconds, which makes it easy to define a function that returns the number of milliseconds, for example:
The code is as follows |
Copy Code |
function Getmillisecond () { List ($s 1, $s 2) = explode (", microtime ()); return (float) sprintf ('%.0f ', (Floatval ($s 1) + floatval ($s 2)) * 1000); } |
It is important to note that the Int maximum value of PHP in a 32-bit system is much smaller than the number of milliseconds, so the int type cannot be used, and PHP does not have a long type, so it has to be represented by floating-point numbers. Due to the use of floating-point numbers, if the accuracy is not set correctly, the results obtained using the echo display may not be correct, and the accuracy setting cannot be less than 13 bits if you want to see the correct output result.
code as follows |
copy code |
/* * Microsecond microsecond Millisecond ms * Returns the number of milliseconds for the timestamp */ function Get_millisecond () { List ($usec, $sec) = Explode ("", Microtime ()); $msec =round ($usec *1000); return $msec;
}
/* * * Returns the number of milliseconds in a string timestamp */ function Get_total_millisecond () { $time = Explode ("", Microtime ()); $time = $time [1]. ($time [0] * 1000); $time 2 = Explode (".", $time); $time = $time 2 [0]; return $time; }
/* * * Returns the current Unix timestamp and the number of microseconds (represented by decimals in seconds) floating-point numbers, commonly used to calculate code snippet execution time */
function Microtime_float () { List ($usec, $sec) = Explode ("", Microtime ()); return (float) $usec + (float) $sec); }
|
It is important to note that the Int maximum value of PHP in a 32-bit system is much smaller than the number of milliseconds, so the int type cannot be used, and PHP does not have a long type, so it has to be represented by floating-point numbers.
http://www.bkjia.com/PHPjc/631498.html www.bkjia.com true http://www.bkjia.com/PHPjc/631498.html techarticle get time and date in PHP we can use the DATE function, and if the milliseconds can be used but not specific, let me introduce some examples of PHP getting the current time milliseconds. ...