show the year with js

just a simple one liner that will show the current year, so no more need for static years in html footers!

var d = new Date();
document.getElementById("year").innerHTML = d.getFullYear();

Usage Example

Copyright ©

Example Code

<div>
Copyright © <span id='year'></span>
</div>

<script type="text/javascript">
var d = new Date();
document.getElementById("year").innerHTML = d.getFullYear();
</script>

A Shorter Way

The above way works ok, but probably is a bit long. Here is a quick one liner.

<span id='year2'></span><script>document.getElementById('year2').innerHTML = (new Date().getFullYear())</script>

Demo

Other Items in js
Page Views

This page has been viewed 43 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹