获取时隔半个钟的三天

摘要:

今天遇到需求是配送时间,时隔半个钟的排线!所以需要拼接时间!例如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
    },
相关推荐
渐儿11 分钟前
NestJS 教程 Part 2 — 数据层、API 设计与业务异步
前端
渐儿15 分钟前
Next.js 教程 Part 2 — 数据获取、Server Actions 与状态
前端
用户1257585243619 分钟前
XYGo Admin ArtTable 表格组件:一行代码搞定加载、刷新与分页
前端
用户114896694410521 分钟前
Promise解析
javascript·面试
gogoing22 分钟前
Prettier 配置说明
前端·javascript
十有八七23 分钟前
Hermes Agent 自进化实现:从源码到架构的深度拆解
前端·人工智能
渐儿23 分钟前
NestJS 生产级开发教程
前端
前端毕业班24 分钟前
uni-app onShareAppMessage hook 原理分析
前端·javascript
gogoing25 分钟前
React 分包加载优化
前端·react.js
gogoing28 分钟前
Babel 配置与工具
前端·javascript