Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在 PHP 中使用 sprintf() 来填充时间(MP3 的播放时间)。
sprintf("%02d:2d:2d", $time);
例如,如果 MP3 的长度为 1 分 56 秒,则返回时间的函数会得到“1:56”,并且该调用会返回“01:56:00”(而它需要是 00:01:56) . 我怎样才能使这项工作?我怎样才能告诉 sprintf 垫在左边?
还是有更好的方法来解决这个问题?也许更合适的功能?
谢谢
我认为您需要分别计算每个元素,那么如何:
sprintf("%02d:%02d:%02d", floor($time/3600), floor($time/60)%60, $time%60);
您可以使用日期功能。
如果 $time 是 unix 时间戳格式,这样的东西应该可以工作:
print(date("H:i:s", $time));
你应该使用strftime($format,$timestamp) ...可能是这样的:
strftime("%H:%M:%S",$time)
问候
back2dos