十分之一秒的日期输出?

Date output for tenth of seconds?

我正在以下列格式将单圈时间存储在数据库中:103.900。

我正在使用以下日期格式从数据库中输出时间:

date('i:s.U', $video->best_lap)

我得到的是:01:43.103。实际输出时间应该显示01:43.900。有什么办法可以让 PHP 玩得很好吗?

PHP 的日期函数(使用整数值的 unix 时间戳)不支持小数秒(如 PHP Docs 中所述)

Note: Since this function only accepts integer timestamps the u format character is only useful when using the date_format() function with user based timestamps created with date_create().

还要注意小数部分格式掩码是u,而不是U(小写,不是大写)

但是,DateTime 对象确实支持小数秒,因此您可以使用:

$dto = DateTime::createFromFormat('U.u', '103.900');
echo $dto->format('i:s.u');