写项目过程中遇到了一个关于秒转化为时分秒格式的问题,当然,我们可以使用外部类获取到视频或者音频的时长,但是作为后端,我们不可能只传给前端一个秒数,而不做任何处理,所以,在百般查找下,发现了一个简单实现的方法,个人觉得很好用,分享给大家。
/**
* 将秒数转化为时分秒格式
*
* @param time
* @return
*/
public static String getVideoFormat(long time) {
int temp = (int) time;
int hh = temp / 3600;
int mm = (temp % 3600) / 60;
int ss = (temp % 3600) % 60;
return (hh < 10 ? ("0" + hh) : hh) + ":" +
(mm < 10 ? ("0" + mm) : mm) + ":" +
(ss < 10 ? ("0" + ss) : ss);
}