Inserting a timestamp using traditional and modern JavaScript methods.
<!DOCTYPE html>
<html>
<body>
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.
</button>
<p id="demo"></p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<body>
<h1>My First JavaScript</h1>
<button type="button" id="dateBtn">
Click me to display Date and Time.
</button>
<p id="demo"></p>
<script>
const btn = document.getElementById('dateBtn');
const output = document.getElementById('demo');
btn.addEventListener('click', () => {
output.textContent = new Date().toLocaleString();
});
</script>
</body>
</html>