dev-resources.site
for different kinds of informations.
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.
src: 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());
- Introduce a script tag in your Footer Section.
<p>
©
<script>
document.write(new Date().getFullYear());
</script>
<a href='https://twiter.com/saviour123>Saviour Gidi<a/>
</p>
Output
Β© 2019 Saviour Gidi
Approach Two
Introduce a script tag with AJAX and get the current Date from World Clock.
<p>
©
<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>
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: