我需要将秒转换为“小时:分钟:秒”。
例如:“685”转换为“00:11:25”
我怎样才能做到这一点呢?
我需要将秒转换为“小时:分钟:秒”。
例如:“685”转换为“00:11:25”
我怎样才能做到这一点呢?
当前回答
如果你需要在javascript中做到这一点,你可以在这里回答的一行代码中做到这一点,用javascript将秒转换为HH-MM-SS。用您想要转换的内容替换SECONDS。
var time = new Date(SECONDS * 1000).toISOString().substr(11, 8);
其他回答
gmdate("H:i:s", no_of_seconds);
如果no_of_seconds大于1天(一天中的秒数),将不会以H:i:s格式给出时间。 它将忽略日值,只给出小时:分钟:秒
例如:
gmdate("H:i:s", 89922); // returns 0:58:42 not (1 Day 0:58:42) or 24:58:42
你可以使用gmdate()函数:
echo gmdate("H:i:s", 685);
给你
function format_time($t,$f=':') // t = seconds, f = separator
{
return sprintf("%02d%s%02d%s%02d", floor($t/3600), $f, ($t/60)%60, $f, $t%60);
}
echo format_time(685); // 00:11:25
试试这个:
date("H:i:s",-57600 + 685);
从 http://bytes.com/topic/php/answers/3917-seconds-converted-hh-mm-ss
使用DateTime的一个简单方法是:
$time = 60; //sec.
$now = time();
$rep = new DateTime('@'.$now);
$diff = new DateTime('@'.($now+$time));
$return = $diff->diff($rep)->format($format);
//output: 01:04:65
这是一个简单的解决方案,让您能够使用DateTime的格式方法。