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

时间:2021-11-13 13:57:12
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;
}

效果图:

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