Как определить, что дата прошла?
В таком формате будет - May 2021
год указан любой. Месяц тоже.
Источник: Stack Overflow на русском
В таком формате будет - May 2021
год указан любой. Месяц тоже.
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;
}
}