常用工具函数

时间类:

  获取时间戳:

var date = new Date();
var time1 = date.getTime();

时间戳转日期:

format(datestr) {
    var shijianchuo = parseInt(datestr);
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y + '-' + this.add0(m) + '-' + this.add0(d) + ' ' + this.add0(h) + ':' + this.add0(mm) + ':' + this.add0(s);
  },
  add0(m) { return m < 10 ? '0' + m : m }

随机数:

  生成四位随机数:


  var shopId="";
for(var i=0;i<4;i++){
        shopId+=Math.floor(Math.random()*10)
}

获取指定范围的随机数:

原文地址:https://www.cnblogs.com/thing/p/9370528.html