实习入职第十二天: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);

return totalSeconds;

}

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

* @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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值