To get the current date and time using JavaScript we have to use
new Date(); //this creates the date object
Assign this object value to the a string and show the value on HTML page.
Code:
new Date(); //this creates the date object
Assign this object value to the a string and show the value on HTML page.
Code:
<!DOCTYPE html>
<html>
<head>
<script>
function fetchDate() {
var val = new Date();
document.getElementById("dateVal").innerHTML=val;
}
</script>
</head>
<body>
<p id="dateVal">
<input type="button" value="Date" onClick="fetchDate()">
</body>
</html>
<html>
<head>
<script>
function fetchDate() {
var val = new Date();
document.getElementById("dateVal").innerHTML=val;
}
</script>
</head>
<body>
<p id="dateVal">
<input type="button" value="Date" onClick="fetchDate()">
</body>
</html>
No comments:
Post a Comment