We can display the present day of the week by using getDay function of the JavaScript date object. Here getDay function will return 0 to 6 based on the day. Number 0 will be returned for Sunday and 1 for Monday.
We will create one day array with all the names of the seven days will be stored. Based on the value returned by getDay function the name of the day will be displayed from the array.
Here is the demo of the getDay function.
Here is the full code of the above demo.
<html>
<head>
<title>(Type a title for your page here)</title>
<script type="text/javascript">
function show_now(){
var my_day=new Date()
//var dt = new Date(\"Aug 16, 2005 05:55:00\");
var day_name=new Array(7);
day_name[0]='Sunday'
day_name[1]=' Monday'
day_name[2]='Tuesday'
day_name[3]='Wednesday'
day_name[4]='Thursday'
day_name[5]='Friday'
day_name[6]='Saturday'
alert ("Today Day is = " + day_name[my_day.getDay()]);
}
</script></head>
<body>
<input type=button value="Show Day" onclick="show_now();">
</body>
</html>