把毫秒转换成时分秒
数据类型例:600000 转换成 10分钟
js代码:
//毫秒转时间(不是日期!!!)
function changeMillisecond(num) {
//注意数据为156000等,int型,根据实际情况在改;
var time ="";
num = num/1000
//毫秒除100变成秒
var check_h = (num/60)/60;
//判断小时
check_h = check_h.toString()
if (check_h.indexOf(".") !=-1){
check_h =check_h.substring(0,check_h.indexOf("."))
check_h = parseInt(check_h);
var check_m =(num-(check_h*60*60))/60;
//判断分钟
check_m = check_m.toString()
if (check_m.indexOf(".") !=-1){
check_m = parseInt(check_m);
var check_s = (num-(check_h*60*60)-(check_m*60));
//判断秒
if (check_h ==0){
if (check_m ==0){
time = check_s + "秒";
} else{
time = check_m + "分钟"+check_s + "秒";
}
}else{
time = check_h + "小时" + check_m + "分钟" + check_s + "秒";
}
}else{
if (check_h ==0){
time =check_m+"分钟";
} else{
time =check_h+"小时"+check_m+"分钟";
}
}
}else{
time = check_h+"小时";
}
return time;
}
//运行代码
console.log(changeMillisecond(600000));
控制台打印
注: 0分钟或0小时或0秒自动删除了。