Answer the question
In order to leave comments, you need to log in
How to get the name of the day of the week of the last day of the month?
function getLastNameDay(year, month){
let date = new Date(year, month + 1, 0);
return date.getDate;
}
function getWeekDay(date) {
let days = ['ВС', 'ПН', 'ВТ', 'СР', 'ЧТ', 'ПТ', 'СБ'];
return days[date.getDay()];
}
Answer the question
In order to leave comments, you need to log in
you can, of course, use getDay instead of getDate and then the day of the week will be displayed as a numeric value. but how to display its name is not entirely clear....
oops, everything seems to work....
function getLastNameDay(year, month){
let date = new Date(year, month + 1, 0);
let days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thurs', 'Fri', 'Sat'];
return days[date.getDay()];
}
console.log(getLastNameDay(2025,02));
I advise you to read the manuals for the Unix program date
- it just does such manipulations. And JS developers are probably close to Unix.
The date "last day of this month", KMK, is defined as "yesterday (the first day of the next month)". However, there is a problem with the next year's release ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question