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

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

WBOY
WBOYOriginal
2016-06-13 09:07:001024Durchsuche

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程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn