编程 PHP 如何输出带微秒的时间

2024-11-18 01:58:41 +0800 CST views 2406
<?php
date_default_timezone_set('PRC');
function udate($format='Y-m-d H:i:s.u', $utimestamp='') {
    empty($utimestamp) && $utimestamp = microtime(true);
    $timestamp = floor($utimestamp);
    $milliseconds = round(($utimestamp - $timestamp) * 1000000);
    return date(preg_replace('#(?<!\\\\)u#', $milliseconds, $format), $timestamp);
}
echo udate('H:i:s.u'); // 12:33:03.599516
echo udate('Y-m-d H:i:s.u'); // 2016-10-16 12:33:03.599684
echo udate('Y-m-d H:i:s.u', 1234567890.654321); // 2009-02-14 07:31:30.654321
复制全文 生成海报 php 编程 PHP 时间处理

推荐文章

使用Vue 3实现无刷新数据加载
2024-11-18 17:48:20 +0800 CST
Python中何时应该使用异常处理
2024-11-19 01:16:28 +0800 CST
html折叠登陆表单
2024-11-18 19:51:14 +0800 CST
jQuery中向DOM添加元素的多种方法
2024-11-18 23:19:46 +0800 CST
如何在Rust中使用UUID?
2024-11-19 06:10:59 +0800 CST
15 个 JavaScript 性能优化技巧
2024-11-19 07:52:10 +0800 CST
批量导入scv数据库
2024-11-17 05:07:51 +0800 CST
如何在 Vue 3 中使用 TypeScript?
2024-11-18 22:30:18 +0800 CST
Nginx 性能优化有这篇就够了!
2024-11-19 01:57:41 +0800 CST
Golang在整洁架构中优雅使用事务
2024-11-18 19:26:04 +0800 CST
利用Python构建语音助手
2024-11-19 04:24:50 +0800 CST
JavaScript设计模式:单例模式
2024-11-18 10:57:41 +0800 CST
Vue3中如何处理跨域请求?
2024-11-19 08:43:14 +0800 CST
Go中使用依赖注入的实用技巧
2024-11-19 00:24:20 +0800 CST
go命令行
2024-11-18 18:17:47 +0800 CST
使用Vue 3和Axios进行API数据交互
2024-11-18 22:31:21 +0800 CST
快手小程序商城系统
2024-11-25 13:39:46 +0800 CST
程序员茄子在线接单