Hello Friends đź‘‹,

Welcome To Infinitbility! ❤️

To get the current month in typescript has the new Date().getMonth() method which will return every time the current month index in number datatype.

we have to just call new Date().getMonth() and it will check the current date and return month index based on the date.

let monthIndex: number = new Date().getMonth();
console.log(monthIndex); // 1 for Feb, 0 for jan

So whenever we have to so month number we have to add 1 in got value from new Date().getMonth().

let monthIndex: number = (new Date().getMonth() + 1);
console.log(monthIndex); // 1 for Jan, 2 for Feb

Now, we know how to get the current month in typescript and the way to hold in a variable.

TypeScript has a new Date() object which is similar to javascript and the date object provides the getMonth() method which will return the month index store in the new date object.

Thanks for reading…