流浪のwolf

卷帝

导航

element输入天数,获取当前时间加上天数 【时间获取】

    handleInput (val) {
      // console.log(this.formModel.ITEM_PM)
      if (!(/[^\d]/g).test(val)) {
        // console.log('非数字')
        // 当前时间加上PM天数
        console.log(val)
        let now = new Date()
        let result = this.defaulTime2(now, Number(val))
        this.formModel.ITEM_PMTIME = result
      }
    },
    defaulTime2 (now, d) {
      //把时分秒设置为0,不需要就直接注释掉就好了
      // now.setHours(0)
      // now.setMinutes(0)
      // now.setSeconds(0)
      now.setDate(now.getDate() + d)
      now = this.formatDate(now)  //用了上面转年月日的方法
      // now = now.toLocaleDateString(); //自带的年月小于10时,没有自动补0,所以用了自己的方法,看自己需要
      return now
    },
    formatDate (date) {
      const year = date.getFullYear()
      const month = date.getMonth() + 1
      const day = date.getDate()
      const hour = date.getHours()
      const mintu = date.getMinutes()
      const second = date.getSeconds()
      return [year, month, day].map(val => {
        // console.log(val)
        return val
      }).join('-') + " " + `${hour}:${mintu}:${second}`
    },

 

posted on 2023-03-20 13:33  流浪のwolf  阅读(17)  评论(0编辑  收藏  举报