# 如何获得2位数字的一年w / Javascript？

## 这个问题的具体答案可以在下面的这一行中find：

` `//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));` `

` `date.getFullYear().toString().substr(2,2);` `

` `var twoDigitsYear = parseInt(date.getFullYear().toString().substr(2,2), 10);` `

` `var twoDigitsCurrentYear = parseInt(new Date().getFullYear().toString().substr(2,2));` `
` `var d = new Date(); var n = d.getFullYear();` `

` `var final = n.toString().substring(2);` `

` `var yy = (new Date().getFullYear()+'').slice(-2);` `
` `var currentYear = (new Date()).getFullYear(); var twoLastDigits = currentYear%100; var formatedTwoLastDigits = ""; if (twoLastDigits <10 ) { formatedTwoLastDigits = "0" + twoLastDigits; } else { formatedTwoLastDigits = "" + twoLastDigits; }` `