- The getMonth() function retun the current month.
- The getFullYear() function return the current year.
- The getHours() function return current hours 24 hour format.
- The getMinutes() function return the current minutes.
Code:-
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Formatted Date & Time</h1>
<p>we can format the date from new Date()</p>
<input type="button" onclick="get_date();" value="Formatted System Date & Time">
<div id="d1"></div>
<script>
function get_date()
{
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1;
var year = today.getFullYear();
var hour = today.getHours();
var minute = today.getMinutes();
document.getElementById('d1').innerHTML = day + "/" + month + "/" + year + " " + hour + ":" + minute;
}
</script>
</body>
</html>
Output:-
Format Date and Time :- Genius Student
Reviewed by Network security
on
June 11, 2019
Rating:
No comments: