English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Il giorno lavorativo è un numero in JavaScript?

weekday

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.

Syntax

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.

Example 1

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>

Output Result

1


Example 2

<html>
<body>
<p id="day"></p>
<script>
   var d = new Date();
   document.getElementById("day").innerHTML = (d.getDay());
</script>
</body>
</html>

Output Result

1
Ti potrebbe interessare