Logo

dev-resources.site

for different kinds of informations.

Automating the Date On Your Footer.

Published at
12/31/2019
Categories
footer
date
newyear
automation
Author
saviour123
Categories
4 categories in total
footer
open
date
open
newyear
open
automation
open
Author
10 person written this
saviour123
open
Automating the Date On Your Footer.

In software engineering, it often said that, once the task is repetitiveπŸ™„, automate it! So must the Β© Copyright Date on the footer be automated.

Footer holds details such as Sitemap, Social Links and Copyright Notice of a site.
Eg.
Footer Sectionsrc: https://www.godlife.com/en

Approach 1

Introduce a JavaScript tag with internal Date API. You can get the current year from the browser JS API, which means you don't have to change every other year.

  • Add the JS script to your HTML

 Date().getFullYear());

Enter fullscreen mode Exit fullscreen mode
  • Introduce a script tag in your Footer Section.


<p>
   &copy
   <script>
      document.write(new Date().getFullYear());
   </script> 
   <a href='https://twiter.com/saviour123>Saviour Gidi<a/>
 </p>


Enter fullscreen mode Exit fullscreen mode

Output

Β© 2019 Saviour Gidi

Approach Two

Introduce a script tag with AJAX and get the current Date from World Clock.



<p>
  &copy
  <p id='copyright'></p>
  Saviour Gidi
</p>

<script>
    fetch('http://worldclockapi.com/api/json/utc/now')
      .then(data => data.json())
      .then(d => 
      document.getElementById('copyright').innerHTML = (new Date(d.currentDateTime).getFullYear())
)
</script>


Enter fullscreen mode Exit fullscreen mode

NB: This second approach is to a response in the comments.

Imagine every year you have to manually change the date on the website. It's not safe for your health and your company's and I pity you🀣. To cut long story short, update your code to include the JS tag!

Featured ones: