You can also use the Date
object to
get the number of the current day of the
week. This is done using the getDay
method. This method returns numbers from
0
to 6
, where week starts
on Sunday and this day is numbered
0
. Monday is day number 1
,
Tuesday is day number 2
, and so on.
Let's see how the getDay
method
works with an example. Let's say today
is Tuesday. Then the following code
will output the number 2
:
let date = new Date();
console.log(date.getDay());
Display the number of the current day of the week.
Determine if the current day of the week is a weekend or a workday.
Find out how many days are left until next Sunday.