获取时隔半个钟的三天

摘要:

今天遇到需求是配送时间,时隔半个钟的排线!所以需要拼接时间!例如2024-10-08 14:30,2024-10-08 15:00,2024-10-08 15:30

bash 复制代码
<el-form-item label="配送时间:" prop="spOrderTime">
    <el-select v-model="form.spOrderTime" clearable style="width: 240px" @change="changeOrderTime">
    <!-- <el-option v-for="item in Config.selectTimeOption" :key="item.value" :label="item.label"
          :value="item.value"></el-option> -->
             <el-option v-for="item in Config.selectTimeOption" :key="item.index" :label="item.value"
                 :value="item.value">
             </el-option>
     </el-select>
</el-form-item>
bash 复制代码
// 获取配送时间数组
    deliveryTimeList() {
      const now = dayjs();// 获取当前时间
      const threeDaysLater = now.add(2, 'day').endOf('day'); //3天后的日期
      const timePoints = [];//每个半小时整点的时间点
      let currentTime = now.startOf('hour');
      // 如果当前时间不是00分或30分,则跳到下一个半小时整点
      if (currentTime.minute() !== 0 && currentTime.minute() !== 30) {
        if (currentTime.minute() < 30) {
          currentTime = currentTime.set('minute', 30);
        } else {
          currentTime = currentTime.add(1, 'hour').startOf('hour');
        }
      }
      // 循环生成每个半小时整点的时间点
      let index=0
      while (currentTime.isBefore(threeDaysLater) || currentTime.isSame(threeDaysLater)) {
        timePoints.push({
          index:index,
          value:currentTime.format('YYYY-MM-DD HH:mm')
        });
        currentTime = currentTime.add(30, 'minute'); 
        index++
      }
      // 赋值
      this.Config.selectTimeOption = timePoints
      this.form.spOrderTime=timePoints[0].value
    },
相关推荐
跟橙姐学代码9 小时前
自动化邮件发送的终极秘籍:Python库smtplib与email的完整玩法
前端·python·ipython
葡萄城技术团队9 小时前
浏览器为啥要对 JavaScript 定时器“踩刹车”?
javascript
我是ed9 小时前
# vue3 实现甘特图
前端
m0_616188499 小时前
el-table的隔行变色不影响row-class-name的背景色
前端·javascript·vue.js
zheshiyangyang9 小时前
Vue3组件数据双向绑定
前端·javascript·vue.js
林克爱塞尔达10 小时前
Linux入门(二)
linux·运维·chrome
xw510 小时前
uni-app项目支付宝端Input不受控
前端·uni-app·支付宝
大翻哥哥10 小时前
Python上下文管理器进阶指南:不仅仅是with语句
前端·javascript·python
IT_陈寒10 小时前
React 性能优化必杀技:这5个Hook组合让你的应用提速50%!
前端·人工智能·后端
再吃一根胡萝卜11 小时前
Git 强制推送指南:新手必读的「危险操作」解析
前端