只能选择当前时间前后30分钟

1.获取年月日时分秒

    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let strDate = date.getDate();
    let hours = date.getHours()
    let minutes = date.getMinutes()
    let seconds = date.getSeconds()
    if (month >= 1 && month <= 9) { month = "0" + month; }
    if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; }
    console.log(year + '年' + month + '月' + strDate+'日'+hours+'时'+minutes+'分'+seconds+'秒')

效果

2.获取当前时间前后30分钟


  created() {
    let date = new Date();//23.59
    console.log(date)
    let month = date.getMonth() + 1;//月份
    let strDate = date.getDate();//天
    let hoursStart = date.getHours();//小时
    let hoursEnd = date.getHours()
    let minutesStart = date.getMinutes() - 30;
    let minutesEnd = date.getMinutes() + 30;
    if (month >= 1 && month <= 9) { month = "0" + month; }
    if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; }
    //  00 : 00  -1    23:10  
    if (minutesStart < 0) {
      hoursStart = hoursStart - 1;
      minutesStart = minutesStart + 60;
      if (hoursStart < 0) {
        this.rangeStart.selectableRange = (`${hoursEnd}:00:00 - ${hoursEnd}:${minutesEnd}:00`);
      }
      this.rangeStart.selectableRange = (`${hoursStart}:${minutesStart}:00 - ${hoursEnd}:${minutesEnd}:00`)
    } else if (minutesEnd > 60) {
      // 23 : 50   24 : 80
      let hoursStart = 23;
      hoursStart = hoursStart + 1;
      minutesStart = Number(minutesEnd) - 60;
      if (hoursStart > 23) {
        this.rangeStart.selectableRange = (`${hoursEnd}:${minutesStart}:00 -23:59:59`);
      }
      this.rangeStart.selectableRange = (`${hoursEnd}:${minutesStart}:00 - ${hoursStart}:${minutesStart}:00`)
      console.log(this.rangeStart.selectableRange)
    }
  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值