tags:

views:

241

answers:

3

I have recently been running into alot of my clients coming to me in the last month asking me to update their Copyright on their sites to reflect 2010.

Is it possible to write a small snippet with jQuery that automatically populated the year? When Jan 1st 2011 rolls around, the text would automatically change from 2010 to 2011?

Thanks.

+3  A: 
$('#spanYear').html(new Date().getFullYear());

The biggest issue being that the client can change the copyright by changing the clock on their own computer ;)

David Hedlund
+1  A: 

another possiblity is to make an ajax-call with jQuery to a "time-service" that will return the time/date/year and use that value to update the webpage.

edit: Yahoo has a timeservice

Natrium
unless OP is actually hosting a site a developer.yahoo.com, wouldn't he need to make a padded JSON request to get that through javascript?
David Hedlund
Cross-domain AJAX is, without any doubt, the easiest and most reliable way to display the current date on a website! ;)
Jørn Schou-Rode
+2  A: 

You could do it via js but as David suggests its easy to manipulate from the client side. it would be better to stamp it on the server side either directly on your server via php or some other dynamic language (this would require change file extensions or config though) or by using an ajax call to a dynamic file on your server or a time service that wil return the year or full date which you can parse the year out of.

Actually you could use SSI directives for something this simple... REally old tech but the downsides of parsing .html as .shtml have waaay fewer reprecussions than changing all your file extenstions or parsing .html as php or some other language. Assuming SSI is available on the server a simple:

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

should do the trick after you make the necessary html -> shtml configuration changes (which i beleive can be done in .htaccess via AddHandler or a similar directive).

prodigitalson