Home >Backend Development >PHP Tutorial >How to get millisecond timestamp in PHP, get milliseconds in php_PHP tutorial

How to get millisecond timestamp in PHP, get milliseconds in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:57:07879browse

How to get millisecond-level timestamps in PHP, get milliseconds in php

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:

<&#63;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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/984615.htmlTechArticleHow to get millisecond timestamps in PHP, how to get milliseconds in php This article describes how to get millisecond timestamps in PHP . Share it with everyone for your reference. The specific analysis is as follows: PHP itself does not...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn