php 精确到毫秒互相转换日期

echo $this->msectime().'</br>';
echo $this->msecdate($this->msectime());


/* 毫秒时间戳转换成日期 */
function msecdate($time)
{
$tag='Y-m-d H:i:s';
   $a = substr($time,0,10);
   $b = substr($time,10);
   $date = date($tag,$a).'.'.$b;
   return $date;
}

//返回当前的毫秒时间戳
function msectime()
 {
     list($msec, $sec) = explode(' ', microtime());
           $msectime =  (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
           return $msectime;
}

效果图:

猜你喜欢

转载自www.cnblogs.com/langzibht/p/9652925.html