Date getDay() method with example in JavaScript

JavaScript Date getDay() method: Here, we are going to learn about the getDay() method of Date class with Example in JavaScript.
Submitted by IncludeHelp, on March 04, 2019

JavaScript Date getDay() method

getDay() method is a Date's class method and it is used to get the current day of the week.

It accepts nothing as the parameter and returns a value between 0 to 6 (based on the day of the week).

Note: The values 0 to 6 based on the weekdays, 0 for Sunday, 1 for Monday, ..., 6 for Saturday

Syntax:

    var dt = new Date();
    dt.getDay();

Examples:

    Input:
    var dt = new Date();
    dt.getDay();
    
    Output:
    1 // if day of Monday

JavaScript code to get the current day of the week using getDay() method

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date(); //Date constructor 
	var wday = dt.getDay(); //getting day of the week
	//printing day
	document.write("Today's weekday is: " + wday);
</script>
</body>
</html>

Output

Today's weekday is: 1

JavaScript Date Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.