1 回答
TA贡献1830条经验 获得超3个赞
var curhour = new Date().getHours();
var hourList = ['8:00-9:00', '9:00-10:00', '10:00-11:00', '11:00-12:00', '12:00-13:00', '13:00-14:00', '14:00-15:00', '15:00-16:00', '16:00-17:00', '17:00-18:00', '18:00-19:00','19:00-20:00'];
var resultHourList;
var foundIndex=hourList.findIndex(function(item){
var start=parseInt(item.split("-")[0].split(":")[0],10);
if(start===curhour){
return true;
}else{
return false;
}
});
if(foundIndex!=-1){
resultHourList=hourList.splice(foundIndex);
}
console.log(resultHourList);
或者
var curhour = new Date().getHours();
var hourList = ['8:00-9:00', '9:00-10:00', '10:00-11:00', '11:00-12:00', '12:00-13:00', '13:00-14:00', '14:00-15:00', '15:00-16:00', '16:00-17:00', '17:00-18:00', '18:00-19:00','19:00-20:00'];
var resultHourList;
var firstHour=parseInt(hourList[0].split("-")[0].split(":")[0],10);
var offset=curhour-firstHour;
resultHourList=hourList.splice(offset);
console.log(resultHourList);
添加回答
举报