Как определить, что дата прошла?

Рейтинг: -4Ответов: 1Опубликовано: 11.06.2023

В таком формате будет - May 2021

год указан любой. Месяц тоже.

Ответы

▲ -1Принят

let chkMonthYear = 'May 2021';
let checkTimestamp = new Date(chkMonthYear).getTime();

let date = new Date();
let nowYear = date.getFullYear();
let nowMonth, nowMonthYear, nowTimestamp;

for (let month = 0; month <= 11; month++) {
    nowMonth = new Date(date.setMonth(month)).toLocaleString('en',{month:'long'}).toString();
    nowMonthYear = nowMonth+' '+nowYear;
    nowTimestamp = new Date(nowMonthYear).getTime();
    console.log(nowMonthYear+' > '+chkMonthYear);
    if (nowTimestamp > checkTimestamp) {
        console.log('Дата '+chkMonthYear+' прошла');
        break;
    }
}