PHP输出时间精确到毫秒
作者:程序员11 时间:2020-07-17 人气:427 QQ交流群\邮箱:1003265987@qq.com
PHP输出时间精确到毫秒
要展示的内容
<?php /** * Created by PhpStorm. * User: jefferyteng * Date: 2018/8/28 * Time: 10:00 */ /*1、直接打印微秒0.24754300 1535423356*/ echo(microtime()); echo ""; /*2、十三位时间戳,包含毫秒1535423356248*/ function msectime() { list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $msectime; } echo msectime(); echo ""; //3、获取当前系统时间并打印 $date = new DateTime(); echo $date->format('Y-m-d H:i:s'); echo ""; /*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 ""; //5、只要毫秒+微秒:247624 function milliseconds($format = 'u', $utimestamp = null) { if (is_null($utimestamp)){ $utimestamp = microtime(true); } $timestamp = floor($utimestamp); $milliseconds = round(($utimestamp - $timestamp) * 1000000);//改这里的数值控制毫秒位数 return $milliseconds; } echo milliseconds();
温馨提示:
欢迎阅读本文章,觉得有用就多来支持一下,没有能帮到您,还有很多文章,希望有一天能帮到您。