php 日期时间类型带毫秒

Posted 周伯通的麦田

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 日期时间类型带毫秒相关的知识,希望对你有一定的参考价值。

<?php
        date_default_timezone_set(‘PRC‘);
        $mtimestamp = sprintf("%.3f", microtime(true)); // 带毫秒的时间戳

        $timestamp = floor($mtimestamp); // 时间戳
        $milliseconds = round(($mtimestamp - $timestamp) * 1000); // 毫秒

        $datetime = date("Y-m-d H:i:s", $timestamp) . ‘.‘ . $milliseconds;
        echo sprintf("%s => %s", $mtimestamp, $datetime);//1523856374.820 => 2018-04-16 13:26:14.820

?>

 

以上是关于php 日期时间类型带毫秒的主要内容,如果未能解决你的问题,请参考以下文章