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

Is the weekday a number in JavaScript?

weekday

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.

Syntax

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.

Example1

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>

Output Result

1


Example2

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

Output Result

1
You May Also Like