Notes

Get Current Year in JavaScript

Edit on GitHub

JavaScript

Local Time (machine)

1var d = new Date();
2var yr = d.getYear           //Returns the two digit year e.g. 14 
3var year = d.getFullYear     //Returns the four digit year e.g. 2014

Universal Time (UTC)

1var d = new Date();
2var yrUTC = d.getUTCYear          //Returns the two digit year
3var yearUTC = d.getUTCFullYear    //Returns the full year

Note: Knowing the difference between local machine time and time according to UTC matters. Let’s say you want to greet a user on New Year’s Day at 12:01 am. If you don’t account for timezone difference you can not correctly greet the user at the right time as they might be in a different time zone (say UCT-7) where the new year hasn’t started yet.