util.js 618 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. require("../common/vendor.js");
  3. function timestampFormatter(inputTime, isPop = false) {
  4. const finalDateObj = {
  5. h: null,
  6. // 小时
  7. m: null,
  8. // 分钟
  9. s: null
  10. // 秒
  11. };
  12. let dec = inputTime / 1e3;
  13. if (dec <= 0) {
  14. dec = 0;
  15. }
  16. let h = Math.trunc(dec / 3600);
  17. h = h < 10 ? "0" + h : h;
  18. let m = Math.trunc(dec % 3600 / 60);
  19. m = m < 10 ? "0" + m : m;
  20. let s = Math.trunc(dec % 3600 % 60);
  21. finalDateObj.h = h;
  22. finalDateObj.m = m;
  23. finalDateObj.s = s;
  24. return isPop ? `${h}小时${m}分${s}秒` : finalDateObj;
  25. }
  26. exports.timestampFormatter = timestampFormatter;