How to get current date in JavaScript?

Easy to use new Date() to get a current Date to new Date object containing the current date and time.

<!DOCTYPE html>
<html>
<body>

<h2>First JavaScript Tutorial</h2>

<button type="button" onclick="document.getElementById('test').innerHTML = new Date();">
Click me.</button>

<p id="test"></p>

</body>
</html>

No comments:

Post a Comment