获取当前时间并格式化输出

 //获取当前时间并且格式化输出
    getTime(){
      let date1=new Date();
      let year=this.appendZero(date1.getFullYear());
      let month=this.appendZero(date1.getMonth()+1)
      let day=this.appendZero(date1.getDate());
      let hours=this.appendZero(date1.getHours());
      let minutes=this.appendZero(date1.getMinutes());
      let seconds=this.appendZero(date1.getSeconds());
      return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds
    },
    //过滤补0
    appendZero(obj) {
      if (obj < 10) {
        return "0" + obj;
      } else {
        return obj;
      }
    },

猜你喜欢

转载自www.cnblogs.com/hy96/p/13203015.html
今日推荐