1 回答

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊
在這種情況下,您將不得不使用帶有字符串和格式的 moment 構(gòu)造函數(shù)來(lái)轉(zhuǎn)換"10:30"為 moment 對(duì)象。
時(shí)刻(字符串,字符串);
const items = [{
"id": 1,
"genre": "Comedy",
"startTime": "10:00",
"endTime": "10:30"
},
{
"id": 2,
"genre": "horror",
"startTime": "22:00",
"endTime": "23:30"
}];
const actives = items.filter(item => {
const startMoment = moment(item.startTime, "HH[:]mm"); // Create moment object
const endMoment = moment(item.endTime, "HH[:]mm"); // Create moment object
return moment().isBetween(startMoment, endMoment); // Compare with current time
});
console.log(actives);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
添加回答
舉報(bào)