日期格式转为 00:00:00
1.封装
var func = { timerConvert(number) { if (number <= 0) { // return "0秒"; return "00:00:00"; } else if (number > 0 && number < 60) { // return number + "秒"; return "00:00:" + func.double(number); } else if (number >= 60 && number < 3600) { let second = number % 60; let minute = Math.floor(number / 60); // return minute + "分钟" + second + "秒"; return "00:" + func.double(minute) + ":" + func.double(second); } else { let temp = number % 3600; let second = temp % 60; let minute = Math.floor(temp / 60); let hour = Math.floor(number / 3600); // return hour + "小时" + minute + "分钟" + second + "秒"; return ( func.double(hour) + ":" + func.double(minute) + ":" + func.double(second) ); } }, }; export default func;
2.调用
import func from "UTIL/commonFunc"; func.timerConvert(duration || 0)
.