0
1.1kviews
Write a JavaScript program to display today's date, time and today's day (eg. Sunday, Monday, ...).
1 Answer
0
13views

Program :

<!DOCTYPE html>
<html>
<header><title>Today's Date, Day & Time</title></header>
<body>
<center>
<script>
var currentDate = new Date();
date = currentDate.getDate();
month = currentDate.getMonth() + 1;
year = currentDate.getFullYear();
document.write("<h1> Date: " + date + "/" + month + "/" + year+"</h1>");
document.write("<br><br>");
var day = currentDate.getDay();
days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
document.write("<h1> Day: " + days[day]+"</h1>");
document.write("<br><br>");
var currentTime = new Date();
hours = currentTime.getHours();
minutes = currentTime.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes;
}
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
document.write("<h1> Time: " + hours + ":" + minutes + " " + suffix+"</h1>");
</script>
</center>
</body>
</html>
Please log in to add an answer.