chatgpt question dayjs compare date range

Use dayjs to compare array format times such as ['01', '02', '03'] to see if they are within the start time ['01', '02', '03'] and end time ['05', '00', ' 00']

 

 

 

import dayjs from 'dayjs';

const startTime = ['01', '02', '03'];
const endTime = ['05', '00', '00'];
const targetTime = ['03', '04', '05'];

const start = dayjs().set('hour', startTime[0]).set('minute', startTime[1]).set('second', startTime[2]);
const end = dayjs().set('hour', endTime[0]).set('minute', endTime[1]).set('second', endTime[2]);
const target = dayjs().set('hour', targetTime[0]).set('minute', targetTime[1]).set('second', targetTime[2]);

const isBetween = target.isSameOrAfter(start) && target.isSameOrBefore(end);
console.log(isBetween); // 输出:true 或 false,表示目标时间是否在开始时间和结束时间之间(包括临界值)

 

Guess you like

Origin blog.csdn.net/weixin_53841730/article/details/131665903