将视频、音乐等时间转化为标准时间00:00:00格式的方法

来源:互联网 发布:福州网络棋牌公司 编辑:程序博客网 时间:2024/05/16 02:08
public static String durationFormat(long duration) {
String result;
final StringBuilder builder = new StringBuilder();
final Formatter formatter = new Formatter(builder, Locale.getDefault());


int totalSec = (int) duration / 1000;


int secs = totalSec % 60;
int minutes = (totalSec / 60) % 60;
int hours = (totalSec / 3600);
builder.setLength(0);
if (hours > 0) {
result = formatter.format("%02d:%02d:%02d", hours, minutes, secs)
.toString();
formatter.close();
return result;
} else {
result = formatter.format("%02d:%02d:%02d", hours, minutes, secs)
.toString();
formatter.close();
return result;
}

}

把毫秒的时间转换为时分秒的形式。

上述方法也是参考网上前人的成果,具体从哪里参考来的,也不太记得了,觉得有用,在此记录之,

0 0