Write a JavaScript program to display the current day and time in the following format
1. Program Name - Write a program to display the current date and time
2. Code Input for Display the Current date and time
2.1. JavaScript html Code
<!--JavaScript to display current Date and Time.-->
<html>
<head>
<title>JavaScript to display current Date and Time.</title>
<script type="text/javascript">
function getCurrentDate(){
var curDate=new Date();
document.getElementById("showDate").innerHTML = curDate.toString();
}
</script>
</head>
<body onLoad='getCurrentDate()' style="text-align: center">
<h1>Get current date using JavaScript.</h1>
<!--Here date and time will display-->
<h2 id="showDate"></h2>
</body>
</html>
2.2. JavaScript Function Code
script type="text/javascript">
function getCurrentDate(){
var curDate=new Date();
document.getElementById("showDate").innerHTML = curDate.toString();
}
</script>
Post a Comment