我想将服务器正常运行时间转换为天:小时:分钟:秒
。我使用这段代码:
var os = require('os');
var uptime = os.uptime();
console.log(convertMS(uptime));
并使用此代码将时间转换为天:
function convertMS(ms) {
var d, h, m, s;
s = Math.floor(ms / 1000);
m = Math.floor(s / 60);
s = s % 60;
h = Math.floor(m / 60);
m = m % 60;
d = Math.floor(h / 24);
h = h % 24;
return { d: d, h: h, m: m, s: s };
};
但是uptime
变量返回给我一个像这样的数字16051.8370378
。这是不正确的。我该怎么办?
最佳答案
关于javascript - Nodejs os.uptime() 返回错误的正常运行时间值(以毫秒为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41908599/