# 实习入职第十二天：MediaPlayer时间之间的转换函数

/**
* 计算连个时间之间的秒数
*/

private static int totalSeconds(String startTime, String endTime) {

String[] st = startTime.split(":");
String[] et = endTime.split(":");

int st_h = Integer.valueOf(st[0]);
int st_m = Integer.valueOf(st[1]);
int st_s = Integer.valueOf(st[2]);

int et_h = Integer.valueOf(et[0]);
int et_m = Integer.valueOf(et[1]);
int et_s = Integer.valueOf(et[2]);

int totalSeconds = (et_h - st_h) * 3600 + (et_m - st_m) * 60
+ (et_s - st_s);

}

/**
* 根据当前选择的秒数还原时间点

* @param args
*/

private static String getCheckTimeBySeconds(int progress, String startTime) {

String return_h = "", return_m = "", return_s = "";

String[] st = startTime.split(":");

int st_h = Integer.valueOf(st[0]);
int st_m = Integer.valueOf(st[1]);
int st_s = Integer.valueOf(st[2]);

int h = progress / 3600;

int m = (progress % 3600) / 60;

int s = progress % 60;

if ((s + st_s) >= 60) {

int tmpSecond = (s + st_s) % 60;

m = m + 1;

if (tmpSecond >= 10) {
return_s = tmpSecond + "";
} else {
return_s = "0" + (tmpSecond);
}

} else {
if ((s + st_s) >= 10) {
return_s = s + st_s + "";
} else {
return_s = "0" + (s + st_s);
}

}

if ((m + st_m) >= 60) {

int tmpMin = (m + st_m) % 60;

h = h + 1;

if (tmpMin >= 10) {
return_m = tmpMin + "";
} else {
return_m = "0" + (tmpMin);
}

} else {
if ((m + st_m) >= 10) {
return_m = (m + st_m) + "";
} else {
return_m = "0" + (m + st_m);
}

}

if ((st_h + h) < 10) {
return_h = "0" + (st_h + h);
} else {
return_h = st_h + h + "";
}

return return_h + ":" + return_m + ":" + return_s;
}

}

public static String getStandardTime(int time) {
time = time/1000;
int h = time / 1000 / 60 / 24;
int m = (time - h * 1000 * 60 * 24) / 1000 / 60;
int s = (time - h * 1000 * 60 * 24 - m * 1000 * 60);
if(time<0){
return "00:00";
}else if(isNum(h)){
return hasTwo(m)+":"+hasTwo(s);
}else{
return hasTwo(h)+":"+hasTwo(m)+":"+hasTwo(s);
}
}

public static boolean isNum(int n){
if (n==0)
return true;
else
return false;
}

public static String hasTwo(int n) {
if ((n >= 10 && n <= 99))
return n+"";
else
return "0"+n;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：实习入职第十二天：MediaPlayer时间之间的转换函数 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)