After javaScript is set to a certain time

Set a task that we have to deal with after a certain time period. The task will not be processed until the time is up.

First define a function

function goOnCount(dateText) {
    let yearTime = new Date(dateText).getTime();
    let now = new Date().getTime();
    return now >= yearTime
}

We are defining a variable to receive the status returned by the calling function

let dateFlag = goOnCount('2023/4/20 11:59:59')  //这里的日期设定为到了时间段

At this time, judge whether dateFlag is true or false.

if(dateFalg == true){
//做对应的事情
}else{
//做对应的事情
}

Guess you like

Origin blog.csdn.net/m0_63873004/article/details/130124080