JQuery - Dynamic Copyright Year

Recently, I came across many of my clients who came to me last month asking me to update my copyright on their sites to reflect 2010.

Is it possible to write a small fragment with jQuery that automatically fills the year? When will it start on January 1, 2011, will the text automatically change from 2010 to 2011?

Thank.

+3
source share
5 answers
$('#spanYear').html(new Date().getFullYear());

The biggest problem is that the client can change the copyright by changing the clock on his own computer;)

+12
source

js, . php, - ( ) ajax , , .

SSI - ... , .html .shtml , .html php . , SSI :

<!--#config timefmt="%Y" -->
<!--#echo var="DATE_LOCAL" -->

, html β†’ shtml ( .htaccess AddHandler ).

+2

another possibility is to make an ajax call with jQuery "time service", which will return the time / date / year and use this value to refresh the web page.

edit : Yahoo has a temporary service

+1
source

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

source: http://the-chronicon.blogspot.com/2015/01/auto-update-of-copyright-year-javascript.html

+1
source

This is what I did with jQuery, and I tried to use only one line:

&copy; <span id="copyright"> <script>$('#copyright').text(new Date().getFullYear());</script> </span>
0
source

Source: https://habr.com/ru/post/1730231/


All Articles