You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

转换含多位小数的Zulu时间时出现日期时间错误的问题

PHP处理Zulu时间的格式化异常问题

我在格式化带9位小数的Zulu时间字符串时,遇到了返回错误时间的问题。示例代码如下:

$yourDate = "2024-07-16T11:29:32.347043421Z";
echo date('Y-m-d h:i:s', strtotime($yourDate));

这段代码执行后会返回1970-01-01 12:00:00,但如果把秒的小数部分改成8位,格式化结果就正常。

我用以下代码临时解决了这个问题,但不确定是否能适配所有场景:

$yourDate = "2024-07-16T11:29:32.347043421Z";
$trimmedDate = substr($yourDate, 0, 26) . "Z";
echo date('Y-m-d H:i:s', strtotime($trimmedDate));

内容的提问来源于stack exchange,提问作者unice

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 19:12:32