我们需要编写一个以秒为单位的JavaScript函数,并返回秒数中包含的小时数和分钟数。
输入
const seconds = 3601;
输出
const output = "1 hour(s) and 0 minute(s)";
以下是代码-
const seconds = 3601; const toTime = (seconds = 60) => { const hR = 3600; const mR = 60; let h = parseInt(seconds / hR); let m = parseInt((seconds - (h * 3600)) / mR); let res = ''; res += (`${h} hour(s) and ${m} minute(s)`) return res; }; console.log(toTime(seconds));
输出结果
"1 hour(s) and 0 minute(s)"