Website Things

Get Current Year using jQuery

Posted on Monday, January 07, 2013
As an alternative to updating the date dynamically, through server-side scripting, this is a method to change the date dynamically using jQuery. I wouldnt recommend using this unless you cant use a server-side language because, even though it works, its won't be 100% accurate to the current date if the computer your on is wrong. Also, make sure you are loading jQuery when using this code or it won't work correctly.

Add this jQuery in the head of your web page:
var currentYear = (new Date).getFullYear();
$(document).ready(function() {
$("#year").text( (new Date).getFullYear() );
});
Add this text where you want the current year to show:
2012