转换含多位小数的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
相关产品推荐
相关产品推荐

