PHP获取当前时间的毫秒数
1 second = 1000 millisecond = 1000,000 microsecond = 1000,000,000 nanosecond php的毫秒是没有默认函数的,但提供了一个microtime()函数,该函数返回包含两个元素,一个是秒数,一个是小数表示的毫秒数,借助此函数,可以很容易定义一个返回毫秒数的函数,例如:
/*
* 获取时间差,毫秒级
*/
function get_subtraction()
{
$t1 = microtime(true);
$t2 = microtime(true);
return (($t2-$1)*1000).'ms';
} /*
* microsecond 微秒 millisecond 毫秒
*返回时间戳的毫秒数部分
*/
function get_millisecond()
{
list($usec, $sec) = explode(" ", microtime());
$msec=round($usec*1000);
return $msec;
}
/*
*
*返回字符串的毫秒数时间戳
*/
function get_total_millisecond()
{
$time = explode (" ", microtime () );
$time = $time [1] . ($time [0] * 1000);
$time2 = explode ( ".", $time );
$time = $time2 [0];
return $time;
}
/*
*
*返回当前 Unix 时间戳和微秒数(用秒的小数表示)浮点数表示,常用来计算代码段执行时间
*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
} 需要注意,在32位系统中php的int最大值远远小于毫秒数,所以不能使用int类型,而php中没有long类型,所以只好使用浮点数来表示。
相关推荐
Phplayers 2020-09-04
URML 2020-04-22
CodingNotes 2019-11-19
Marsdanding 2019-06-06
kinglee 2019-09-07
DrSmart 2015-08-10
xiaozhifree 2019-07-09
刘炳昭 2019-07-01
AI人工智能 2019-06-28
nxcjh 2019-06-29
mrsuddenflash 2013-09-09
Phplayers 2019-06-28
WindChaser 2019-06-27
pengfeibeiming 2019-06-27
自由飞翔 2014-09-09
solarLan 2019-06-26