php获取时间的方式是time();
那么如果是涉及需要精细的时间的应用,那么怎么获取呢?
/** 获取当前时间戳,精确到毫秒 */
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
/** 格式化时间戳,精确到毫秒,x代表毫秒 */
function microtime_format($tag, $time)
{
list($usec, $sec) = explode(".", $time);
$date = date($tag,$usec);
return str_replace('x', $sec, $date);
}
使用方法: 1. 获取当前时间戳(精确到毫秒):microtime_float() 2. 时间戳转换时间:microtime_format('Y年m月d日 H时i分s秒 x毫秒', 1270626578.66000000)
这里需要用到的是list()函数
list()定义和用法
list() 函数用于在一次操作中给一组变量赋值。 注释:该函数只用于数字索引的数组,且假定数字索引从 0 开始。