How to Auto Update Copyright Year on Your Website

How to Auto Update Copyright Year on Your Website

Timonwa Akintokun Timonwa Akintokun

2 min read

Part of series: The Toolbox


Code

<body>
  <p>
    All Rights Reserved,
    <span id="currentYear"></span>
    <a href="https://tech.timonwa.com">Timonwa Akintokun</a>.
  </p>

  <script>
    let date = new Date().getFullYear();
    document.getElementById("currentYear").textContent = date;
  </script>
</body>

For HTML projects, you can use the above code snippet to update the year automatically on your website.

const Footer = () => {
  let date = new Date().getFullYear();

  return (
    <p>
      All Rights Reserved, {date}.{" "}
      <a href="https://tech.timonwa.com">Timonwa Akintokun</a>.
    </p>
  );
};

You can use the above code snippet for React projects to automatically update the year on your website.

Explanation

The JavaScript Date() object captures the current date and time. Afterward, the getFullYear() method extracts the current year from the obtained date and time. The identified year is stored in a variable named date.

Updating the copyright year is more than just a legal formality; it is a crucial indicator of your commitment to maintaining and protecting your content. Here’s why keeping the copyright year current is essential:

  1. Accurate Protection: A current copyright year ensures that you accurately claim protection for your original work, providing a clear timeframe for your exclusive rights.

  2. Relevance Signaling: A recent copyright year signals to your audience that your content is up-to-date and relevant. It shows that you actively manage and maintain your website.

  3. Legal Compliance: Regularly updating the copyright year demonstrates your commitment to legal compliance, reinforcing your dedication to respecting intellectual property laws.

By incorporating the provided JavaScript snippet into your website’s footer, you automate the process, ensuring that your copyright year is always current without manual intervention.


If this article helped you, it might help someone else too. Click the share button below to spread the word!
Got thoughts or questions? Lets connect on X or LinkedIn.
Till next time, happy coding! 😊

Man waving goodbye


Enjoyed this article?

Be the first to get new blog posts, tutorials, and developer productivity tips delivered to your inbox.

More posts in web development