Heim  >  Artikel  >  Backend-Entwicklung  >  php毫秒时间戳计算方法,php怎么获取毫秒时间戳

php毫秒时间戳计算方法,php怎么获取毫秒时间戳

WBOY
WBOYOriginal
2016-07-25 08:51:172035Durchsuche
php获取毫秒时间戳的例子,php编程中time函数可以取得时间戳,比较了php获取毫秒时间戳的不同写法与效率,感兴趣的朋友参考下。

php毫秒时间戳计算方法

php中time()函数获取的时间戳,其单位是秒.

前端js获取的时间戳,单位是毫秒.

如何将JS和PHP的时间戳统一,即如何使用PHP获取毫秒时间戳?

例子:

复制代码 代码示例: "; echo getMillisecond_new().' PHP毫秒-getMillisecond_new()'; /* * 思路: * 1.使用microtime()获取微秒时间戳,格式:0.69718900 1420440552 * 2.前后两部分相加×1000,然后四舍五入round($float,0) * 秒time()-->毫秒-->微秒microtime(),两两之间是1000进制 * 这样,就可以与前端JS的时间戳保持一致 * JS : new Date().getTime()获得毫秒时间戳 */ ?> time
<script> var time=new Date(); var mtime=time.getTime(); document.write(mtime+' JS获得毫秒时间戳'); </script>

运行结果: 1424069168633 PHP毫秒-getMillisecond() 1424069168633 PHP毫秒-getMillisecond_new() 1424069168643 JS获得毫秒时间戳 可以看出,第三个时间戳数值稍微比前两个大,这是代码运行所消耗的时间,是正常的.



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