e-date-picker限制到时分秒

限制时分秒代码

startTime (index) {
        const self = this
        if (self.tableData[index].expirationTime) {
          const startTime = self.tableData[index].effectiveTime
          const endTime = self.tableData[index].expirationTime
          const HH = new Date(endTime).getHours()
          const MM = new Date(endTime).getMinutes()
          const ss = new Date(endTime).getSeconds()
          const isSameDay = new Date(startTime).toDateString() === new Date(endTime).toDateString()
          return {
            disabledDate (time) {
              if (self.tableData[index].expirationTime) {
                // 如果结束时间不为空,则小于结束时间
                // 替换的目的(时间 2020-09-09 在IE中不支持; 2020/09/09 在IE中支持)
                // self.formData.syncTimeE = self.formData.syncTimeE.replace(/-/g, '/')
                const lastTime = new Date(self.tableData[index].expirationTime).getTime() // 选中的时间
                if (lastTime < Date.now()) {
                  return lastTime < time.getTime()
                } else {
                  // 开始时间不得超过当前天,如果开始时间可以大于当前时间,直接注释当前代码即可
                  return time.getTime() > Date.now()
                }
              } else {
                return time.getTime() > Date.now() // 开始时间不选时,结束时间最大值小于等于当天
              }
            },
            selectableRange: isSameDay ? '00:00:00 - ' + HH + ':' + MM + ':' + ss : '00:00:00 - 23:59:59'
          }
        }
      },
      endTime(index) {
        const self = this
        if (self.tableData[index].effectiveTime) {
          const startTime = self.tableData[index].effectiveTime
          const endTime = self.tableData[index].expirationTime
          const HH = new Date(startTime).getHours()
          const MM = new Date(startTime).getMinutes()
          const ss = new Date(startTime).getSeconds()
          console.log(HH, MM, ss)
          const isSameDay = new Date(startTime).toDateString() === new Date(endTime).toDateString()
          return {
            disabledDate (time) {
              if (self.tableData[index].effectiveTime) {
                // return new Date(self.tableData[index].effectiveTime).getTime() - 86400 > time.getTime()
                return HH === 0 && MM === 0 && ss === 0 ? new Date(startTime).getTime() > time.getTime() : new Date(startTime).getTime() - 86400000 > time.getTime()
              }
            },
            selectableRange: isSameDay ? HH + ':' + MM + ':' + ss + ' - 23:59:59' : '00:00:00 - 23:59:59'
          }
        }
      }

限制时分秒代码中有index参数,是因为我这段代码是在表格中做的处理,index算是个下标

return HH === 0 && MM === 0 && ss === 0 ? new Date(startTime).getTime() > time.getTime() : new Date(startTime).getTime() - 86400000 > time.getTime()

如果HH;MM;ss不为0,需要减去一天的毫秒数86400000,否则当天的日期不可选择

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值