美文网首页
js根据起始和截止时间和间隔时间 计算预约时间段

js根据起始和截止时间和间隔时间 计算预约时间段

作者: 爱学习的小仙女早睡早起 | 来源:发表于2022-07-07 10:43 被阅读0次

js根据起始和截止时间和间隔时间 计算预约时间段

image
// 查询预约配置
    getConfig(){
        this.morningTimePeriodStart = "2022-07-06 9:00"
        this.morningTimePeriodEnd = "2022-07-06 12:00"
        this.step = "10"
        this.afternoonPeriodStart = "9:00"
        this.afternoonPeriodEnd = "12:00"
        this.workDays = ["1", "2", "3", "4", "5", "6", "7"]
        let arr=this.computeBtnTime(this.morningTimePeriodStart, this.morningTimePeriodEnd, this.step)
        console.log(11222333, arr)
},

 // 计算可选时段
computeBtnTime(startDate, endDate, space){ // space分钟
        const startTime = new Date(startDate).getTime()   // 将开始时间 转换成时间戳
        const endTime = new Date(endDate).getTime()
        let n = 1
        let step = 0
        let date = null
        let newStartTime = 0
        let attrTime=[]
        let time1=`${new Date(startDate).getHours()}:${new Date(startDate).getMinutes()==0?'00':new Date(startDate).getMinutes()}:`
        let time2=""
        while(newStartTime < endTime ){
            step = Number(space)* n * 60 *1000 // 将时间间隔转换为时间戳
            date = new Date(startTime + step) // 计算新时间
            newStartTime = new Date(startTime + step).getTime() // 新时间的时间戳
            time2 = `${date.getHours()}:${date.getMinutes()==0?'00':date.getMinutes()}`
            attrTime.push(`${time1}~${time2}`)
            time1=time2
            n++
        }

        return attrTime
    },

image

相关文章

网友评论

      本文标题:js根据起始和截止时间和间隔时间 计算预约时间段

      本文链接:https://www.haomeiwen.com/subject/zpaubrtx.html