PHP如何获取带毫秒的时间戳

已邀请:
匿名用户

匿名用户

赞同来自:

1、PHP5.0以上版本:
<?php
$millisecond = sprintf("%.3f", microtime(true));
$microsecond = sprintf("%.6f", microtime(true));
echo sprintf("带毫秒时间戳: %s\n", $millisecond); //1476438877.679
echo sprintf("带微秒时间戳: %s\n", $microsecond); //1476438500.760217

 2、PHP5.0以下版本:
<?php
list($t1, $t2) = explode(' ', microtime());
$millisecond = sprintf("%d.d", $t2, $t1*1000);
$microsecond = sprintf("%d.d", $t2, $t1*1000000);
echo sprintf("带毫秒时间戳: %s\n", $millisecond); //1476438500.760
echo sprintf("带微秒时间戳: %s\n", $microsecond); //1476438877.678877

要回复问题请先登录注册