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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *