Categories
TypeScript Answers

How to get the current year using TypeScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.