<!DOCTYPE html>
<html>
<head>
<title>How to get current date in JavaScript?</title>
</head>
<body style=" text-align:center;">
<h1 style="color: green">
GeeksforGeeks
</h1>
<b>
How to get current date in JavaScript?
</b>
<p>
Current date/time in milliseconds is:
<span class="output-msecs">
</p>
<p>
Current date/time in seconds is:
<span class="output-secs">
</p>
<p>
Current date/time in words is:
<span class="output-words">
</p>
<button onclick="getCurrentDate()">Get current time</button>
<script type="text/javascript">
function getCurrentDate() {
dateInMillisecs = new Date().getTime();
dateInSecs = Math.round(dateInMillisecs / 1000);
dateInWords = new Date(dateInMillisecs);
document.querySelector('.output-msecs').textContent =
dateInMillisecs;
document.querySelector('.output-secs').textContent =
dateInSecs;
document.querySelector('.output-words').textContent =
dateInWords;
}
</script>
</body>
</html>