How to use getDay in JavaScript

In this article, I will explain use of getDay () Method in JavaScript.
  • 1692

JavaScript date getDay() method

  • getDay() method of date object returns the day of the week for the specified date according to local time.

  • In getDay() method, The returned value is an integer corresponding to the day of the week.

Syntax

Date.getDay()

Example

In the following example show to getDay() method returns current day of week.

<!DOCTYPE html>

<html>

<body>

<h3 style="color:Blue">JavaScript getDay() Method Example</h3>

<p id="demo">Click the button to display todays day of the week.</p>

<button onclick="myFunction()">Click On</button>

<script type="text/javascript">

    function myFunction() {

        var d = new Date();

        var weekday = new Array(7);

        weekday[0] = "Sunday";

        weekday[1] = "Monday";

        weekday[2] = "Tuesday";

        weekday[3] = "Wednesday";

        weekday[4] = "Thursday";

        weekday[5] = "Friday";

        weekday[6] = "Saturday";

        var x = document.getElementById("demo");

        x.innerHTML= document.write("Today Day is: " + weekday[d.getDay()]);

    }

</script>

</body>

</html>

Output1

getDay 1.jpg

Output2

getDay 2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.