Print current year in JavaScript
Printing the numerical representation of the present year into an HTML element by means of JavaScript and getFullYear() method:
HTML code:
<div class="example">
<p></p>
</div>
JavaScript code:
<script>
document.querySelector('.example p').textContent = new Date().getFullYear();
</script>
Browser support
- Windows
- Edge 12.0+
- Firefox 3.5+
- Google Chrome 1.0+
- Opera 10.0+
- Linux
- Firefox 3.5+
- Google Chrome 1.0+
- Opera 10.0+
- iOS
- Safari 2.0+
- Android
- Samsung Internet 1.0+
- Chrome Android 18.0+
- Firefox for Android 4.0+
- Opera Android 10.1+