How to get the current year using typescript in angular6

Revathi Vijay picture Revathi Vijay · Aug 29, 2018 · Viewed 52.5k times · Source

How to get the current year using typescript in angular6

currentYear:Date;
this.currentYear=new Date("YYYY");
alert(this.currentYear);

It shows Invalid Date

Answer

Sajeetharan picture Sajeetharan · Aug 29, 2018

Try,

 alert((new Date()).getFullYear());