PHP时间戳与时间相互转换(精确到毫秒)

kevin.Zhu 发布于:2013-1-16 15:33 分类:Php  有 12 人浏览,获得评论 0 条  

/** 获取当前时间戳,精确到毫秒 */
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