如何在JavaScript中向HH:MM:SS添加分钟?

我想将分钟(typeof Integer)添加到HH:MM:SS(typeof String)。

例:

let min = 125;
let time = "10:00:00";

结果=“ 12:05:00”

评论
gomnis
gomnis

Make a new Date object and then set the time with setHours().

let time = new Date();
// pass hours, minutes, seconds and account for local time zone
// I'm GMT-4 so I pass 16 to get to 20
time.setHours(16,5,0);
console.log(time);
点赞
评论