How To Get Current Day In Javascript?


Share:
Published By: Admin, Published On: Aug 05, 2021, Category: Javascript

Hello Friends,

Now let's see example of how to use javascript get current day example. We will use how to use if get current day in javascript. Here you will learn how to use javascript get current day. This is a short guide on get current day. Let's get started with how to get current day in javascript.

Here i will give you many example how you can check javascript get current day.

Example: 1
<!DOCTYPE html>
<html>
    <head>
        <title>How to get current day? - MyWebtuts.com </title>
        <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    </head>
    <body class="bg-dark">
        <div class="container mt-5">
            <div class="row">
                <div class="col-md-6 offset-md-3">
                    <div class="card">
                        <div class="card-header">
                            <h4>JavaScript get current day</h4>
                        </div>
                        <div class="card-body">
                            <p>Click the button to display todays day of the week.</p>
                            <button onclick="cmp()" class="btn btn-primary mb-2">Check it</button>
                            <p id="tst"></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            function cmp() {
                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 n = weekday[d.getDay()];
                document.getElementById("tst").innerHTML = n;
            }
        </script>
    </body>
</html>
Output:
Monday
Example: 2
<!DOCTYPE html>
<html>
  	<head>
	  	<meta charset="utf-8">
	  	<title>How to get current day? - MyWebtuts.com </title>
  	</head>
  	<body>
	  	<script type="text/javascript">
	  		var today = new Date();
		  	var day = today.getDay();
		  	var daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"];
		  	console.log("Today is : " + daylist[day] + ".");
	  	</script>
  	</body>
</html>
Output:
Today is : Monday.

It will help you....

Share: