整型转时分秒
//将长度转换为时间
StringBuilder mFormatBuilder = new StringBuilder();
Formatter mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
//将长度转换为时间
private String stringForTime(int timeMs) {
int totalSeconds = timeMs / 1000;
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
mFormatBuilder.setLength(0);
if (hours > 0) {
return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString();
} else {
return mFormatter.format("%02d:%02d", minutes, seconds).toString();
}
}
时分秒转整型
private int wav(String str){
String str1[] = str.split(":");
//0->时,1->分,2->秒
int m = Integer.parseInt(str1[2]);
int f = Integer.parseInt(str1[1])*60;
int s = Integer.parseInt(str1[0])*60*60;
int miao = (m+f+s)*1000;
return miao;
}
本文介绍了如何在Java中实现将整数秒转换为时分秒格式的字符串,以及将字符串解析回整数秒的实用函数。通过实例展示了时分秒转整型和整型转时间的详细步骤,适合开发者进行时间处理的快速参考。

被折叠的 条评论
为什么被折叠?



