用JavaScript将秒转换为HH-MM-SS?如何将秒转换为HH-MM-SS使用JavaScript的字符串?
3 回答
浮云间
TA贡献1829条经验 获得超4个赞
hours = Math.floor(totalSeconds / 3600);totalSeconds %= 3600;minutes = Math.floor(totalSeconds / 60);seconds = totalSeconds % 60;
let totalSeconds = 28565;let hours = Math.floor(totalSeconds / 3600);totalSeconds %= 3600;let minutes = Math.floor(totalSeconds / 60); let seconds = totalSeconds % 60;console.log("hours: " + hours);console.log("minutes: " + minutes);console.log("seconds: " + seconds); // If you want strings with leading zeroes:minutes = String(minutes).padStart(2, "0");hours = String(hours).padStart(2, "0"); seconds = String(seconds).padStart(2, "0");console.log(hours + ":" + minutes + ":" + seconds);
添加回答
举报
0/150
提交
取消