<?php/** * Created by PhpStorm. * User: jefferyteng * Date: 2018/8/28 * Time: 10:00 *//*1、直接打印微秒0.24754300 1535423356*/echo(microtime());echo "<br/>";/*2、十三位时间戳,包含毫秒1535423356248*/function msectime(){list($msec, $sec) = explode(' ', microtime());$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);return $msectime;}echo msectime();echo "<br/>";//3、获取当前系统时间并打印$date = new DateTime();echo $date->format('Y-m-d H:i:s');echo "<br/>";/*4、完整的时间:2018-08-28 10:29:16 247591*/function udate($format = 'u', $utimestamp = null){if (is_null($utimestamp)){$utimestamp = microtime(true);}$timestamp = floor($utimestamp);$milliseconds = round(($utimestamp - $timestamp) * 1000000);//改这里的数值控制毫秒位数return date(preg_replace('`(?<!\\\\)u`', $milliseconds, $format), $timestamp);}echo udate('Y-m-d H:i:s u');echo "<br/>";//5、只要毫秒+微秒:247624function milliseconds($format = 'u', $utimestamp = null){if (is_null($utimestamp)){$utimestamp = microtime(true);}$timestamp = floor($utimestamp);$milliseconds = round(($utimestamp - $timestamp) * 1000000);//改这里的数值控制毫秒位数return $milliseconds;}echo milliseconds();
PHP输出时间精确到毫秒
最新推荐文章于 2023-01-13 23:07:30 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)