Home >Backend Development >PHP Tutorial >How to get millisecond timestamp in PHP, get milliseconds in php_PHP tutorial
The example in this article describes how to get millisecond-level timestamps in PHP. Share it with everyone for your reference. The specific analysis is as follows:
PHP itself does not provide a function to obtain millisecond-level timestamps. It can be obtained through gettime(); in Java. If you want to perform high-precision millisecond-level docking communication with certain programs written in Java, you need to use PHP to output millisecond-level time. The method I took before was to use an imprecise method, which was to add a three-digit number after PHP's native time function. To obtain a more accurate millisecond-level timestamp, you can use the following code:
<?php function getMillisecond() { list($t1, $t2) = explode(' ', microtime()); return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000); } echo getMillisecond();
I hope this article will be helpful to everyone’s PHP programming design.