C
C
coder562020-07-17 13:59:38
JavaScript
coder56, 2020-07-17 13:59:38

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()];
}

There are two functions. one defines the last day of the month, the second - the day of the week. how to combine them to get the day of the week of the last month?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
coder56, 2020-07-17
@coder56

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));

K
Karpion, 2020-07-17
@Karpion

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 question

Ask a Question

731 491 924 answers to any question