Home  >  Article  >  php教程  >  PHP获取毫秒级时间戳的方法,php获取毫秒

PHP获取毫秒级时间戳的方法,php获取毫秒

WBOY
WBOYOriginal
2016-06-13 09:07:001030browse

PHP获取毫秒级时间戳的方法,php获取毫秒

本文实例讲述了PHP获取毫秒级时间戳的方法。分享给大家供大家参考。具体分析如下:

PHP本身没有提供获取毫秒级时间戳的函数,java里面可以通过gettime();获取。如果是要与java写的某些程序进行高精度的毫秒级的对接通信,则需要使用PHP输出毫秒级的时间。之前我采取的方法是采用不精准的方式,也就是在PHP原生的时间函数后面加上一个三位数字构成。为获取更为精准的毫秒级时间戳可以使用下面的代码:

<&#63;php
function getMillisecond() {
list($t1, $t2) = explode(' ', microtime());
return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
}
echo getMillisecond();

希望本文所述对大家的php程序设计有所帮助。

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