English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
fromMonday to Sundayeach day of the week, with numbers ranging from1to7.Javascriptthe date objectprovidesThe getDay() methodto get the day of the week. Let's discuss it briefly.
var d = getDay();
It does not take any parameters and only provides working days. If a day is Monday, then it will provide1, if it's Tuesday, then it will provide2, and so on.
In the following example, the date object and its methods are used to calculate the day of the week. My code runs on a Monday. Therefore, the output is1. getDay()
<html> <body> <script> var d = new Date(); document.write(d.getDay()); </script> </body> </html>
1
<html> <body> <p id="day"></p> <script> var d = new Date(); document.getElementById("day").innerHTML = (d.getDay()); </script> </body> </html>
1