javascript - Nodejs os.uptime() 返回错误的正常运行时间值(以毫秒为单位)

标签 javascript node.js milliseconds uptime

我想将服务器正常运行时间转换为天:小时:分钟:秒。我使用这段代码:

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。这是不正确的。我该怎么办?

最佳答案

特别感谢@jcaron

在版本 v6.9.4 中,正常运行时间返回。我犯了一个错误。

v6.9.4 Documentation

关于javascript - Nodejs os.uptime() 返回错误的正常运行时间值(以毫秒为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41908599/

相关文章:

javascript - 如何让 jQuery 验证以验证浏览器预填充的字段

javascript - jQuery 代码仅触发一次

JavaScript 日期 getSeconds 返回 0

python - 如何在 Python 中将毫秒时间戳转换为正常日期?

javascript - 使用 javascript 将 HTML 代码添加到 div 中

javascript - Jest : test Intl. DateTimeFormat

node.js - 如何在 Microsoft Bot 服务中使用直线发布到网络聊天?

node.js - Node js 启动和停止windows服务

mysql - 我如何使用 Sequelize 在 NODE 中执行多个查询(更新)?

milliseconds - MPV 播放器时间格式 HH :MM:SS or HH:MM:SS:mmm