获取时隔半个钟的三天

摘要:

今天遇到需求是配送时间,时隔半个钟的排线!所以需要拼接时间!例如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
    },
相关推荐
API快乐传递者14 分钟前
1688 跨境电商 API 接口实战指南:从寻源到代采的全链路技术方案
java·前端·数据库
马可家的菠萝20 分钟前
收藏不是终点:一个真正有用的个人知识库,至少要完成“收集 → 理解 → 行动”
前端·后端·架构
明月_清风1 小时前
看完 DSH 文档后,我总结了这 7 个关键点
前端·后端·deepseek
qq_452396231 小时前
第八篇:《Monorepo 实战:Turborepo 与 pnpm workspace 驱动的大型项目协作》
前端
数据狐(Datafox)1 小时前
1688.item_search工程实战:1688商品列表API分页采集与B2B货源数据分析落地
java·前端·数据分析
铁皮饭盒1 小时前
浏览器AI肯定离不开onnxruntime, 微软开源
前端·javascript·后端
vivo互联网技术1 小时前
vivo 广告小游戏:从"写代码"到"说需求"
前端·人工智能·游戏开发
李可以量化1 小时前
Redis Client 从了解到精通(二)上:redis-py 高级用法与核心命令实战
前端·数据库·redis·python·缓存·ptrade
码视野1 小时前
基于 Vue3 + Element Plus 的【智慧社区洗车养车与上门流动洗车预约调度系统】设计与实现(含PRD/三端源码/大屏)
前端·javascript·vue.js·人工智能·vue3