How to get the current year using typescript in angular6
Try,
alert((new Date()).getFullYear());
Try this
year = new Date().getFullYear()
console.log(this.year) // output 2020
Since Year is number.
currentYear: number=new Date().getFullYear();
You can try this:
In the app.component.ts.
export class AppComponent {
anio: number = new Date().getFullYear();
}
In the app.component.html
{{ anio }}
I let you a Stackblitz.
https://stackblitz.com/edit/angular-byvzum