How To Auto Update Current Year On Footer In React JS

Manish Jain
2 min readJan 6, 2022

--

Hi folks, React has been developing and becoming more powerful day by day. Major big companies like Facebook, Airbnb, Netflix etc… has shifted to React because it is easy to use and faster.

Tired of changing the current year in footer manually? Sometimes you might even forget to change the current year and you end up being the one who has an outdated copyright year in the footer.

To auto update your current year in the footer you can just make use of the Date Object.

In React JS you can declare a variable shown below in the example and using that variable you can render the current year which will auto update so that you don’t need to update it manually.

let currentYear = new Date().getFullYear()

In HTML 4 & 5 you can make use of the same Date object but the syntax will differ from React JS.

HTML 4

<script type="text/javascript">document.write( new Date().getFullYear() );</script>

HTML 5

<script>document.write( new Date().getFullYear() );</script>

To get the current year in UTC you can use getUTCFullYear() function instead of getFullYear() function

Finally, this is how you can auto update your current year in the footer with just single line of code. I hope you find this helpful.

--

--

Manish Jain
Manish Jain

Written by Manish Jain

React - Node - Developer - Freelancer - Blogger. Eat. Sleep. Code. Repeat.

No responses yet