首页 > 其他分享 >element输入天数,获取当前时间加上天数 【时间获取】

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

时间:2023-03-20 13:47:41浏览次数:34  
标签:const log val 天数 element 获取 date console now

    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}`
    },

 

标签:const,log,val,天数,element,获取,date,console,now
From: https://www.cnblogs.com/zhulongxu/p/17235984.html

相关文章