我有一个时间计算器,它以下列格式返回时间的输入类型:hh/mm/ss
目前显示如下:
Let time = "03:00:00"
当我执行计算函数时,它返回“3:0:0”并删除“0”。
如何将其更改为 03:00:00?仅当 h/m/s 小于 10 时才必须添加“0”。
如果需要,这是我的计算函数。该函数返回数组的时间总和:
let testOne = ["02:00:00", "01:00:00", "01:00:00"]
function test () {
let calTotalHours = testOne.map(t => t.split(':')).reduce((arr,item,index)=>{
arr[0]+= parseFloat(item[0]);
arr[1]+= parseFloat(item[1]);
arr[2]+= parseFloat(item[2]);
if(arr[2]>=60) {
arr[1]++;
arr[2]%=60;
}
if(arr[1]>=60) {
arr[0]++;
arr[1]%=60;
}
return arr;
},[0,0,0])
.join(':')
console.log(calTotalHours)
}
临摹微笑
茅侃侃
富国沪深
相关分类