Sometimes, we want to get the current year using TypeScript.
In this article, we’ll look at how to get the current year using TypeScript.
How to get the current year using TypeScript?
To get the current year using TypeScript, we use the date’s getFullYear
method.
For instance, we write
const y = new Date().getFullYear();
to create a new Date
instance and call getFullYear
to return the 4 digit year number from the date.
Conclusion
To get the current year using TypeScript, we use the date’s getFullYear
method.