utilswxs.wxs 1.25 KB
var filter = {
  // 分转元
  Fen2Yuan: function (val) {
    var result = val * 0.01; //分到元
    // result += ''; //转成字符串
    // result = result.toFixed(2); //留两位小数
    return result.toFixed(2);
  },
  // 毫秒转格式
  msTimeFormat: function (val, day = true) {
    // var result = (val / 60 / 1000) + "分钟";
    var t = val;
    if (t <= 0) return "-";
    var d = Math.floor(t / 1000 / 60 / 60 / 24);
    var h = Math.floor(t / 1000 / 60 / 60 % 24) + (day ? 0 : 24 * d); // 含日的话,就不用24*d了
    var m = Math.floor(t / 1000 / 60 % 60);
    var s = Math.floor(t / 1000 % 60);
    var zeroStr = "";
    var dStr = d + "";
    var hStr = h < 10 ? zeroStr + h : h;
    var mStr = m < 10 ? zeroStr + m : m;
    var sStr = s < 10 ? zeroStr + s : s;
    var result = "";
    if (d > 0 && day) {
      result = dStr + "天" + hStr + "时" + mStr + "分" + sStr + "秒";
    } else {
      if (h > 0) {
        result = hStr + "时" + mStr + "分" + sStr + "秒";
      } else {
        if (m > 0) {
          result = mStr + "分" + sStr + "秒";
        } else {
          result = sStr + "秒";
        }
      }
    }

    return result;
  }
}

module.exports = {
  Fen2Yuan: filter.Fen2Yuan,
  msTimeFormat: filter.msTimeFormat,

}