Ad Code

How to get 2 digit year Javascript

The specific answer to this question is found in this one line below:

//pull the last two digits of the year
//logs to console
//creates a new date object (has the current date and time by default)
//gets the full year from the date object (currently 2017)
//converts the variable to a string
//gets the substring backwards by 2 characters (last two characters)    
console.log(new Date().getFullYear().toString().substr(-2));
<script>document.write(new Date().getYear().toString().substr(-2));</script>

Post a Comment

0 Comments