English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
fromMonday to Sundayof the week, the numbers are from1 to 7.Javascriptdate objectprovidesgetDay() Methodto get the day of the week. Let's discuss it briefly.
var d = getDay();
It does not take any parameters and only provides weekdays. If a day is Monday, it will provide 1, if Tuesday, it will provide 2, and so on.
In the following example, calculate the day of the week using the date object and its methods. My code runs on a Monday. Therefore, the output is 1. 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