当前位置:主页 > >

php 日期时间类型带毫秒

时间:2019-11-27 13:53:38 | 栏目: | 点击:

我们在生成流水号的场景下,经常用到时间戳来表示,请看本文介绍的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

?>

您可能感兴趣的文章:

相关文章