'How do I Determine The Number Of Days In A Month from a particular date in angularjs 2?

I am using angularjs 2 and type script.
I want the number of days in a month from a particular date given by user.
How do I Determine that?
Please help. Thanks in Advance.



Solution 1:[1]

As pointed out by Evgeny Shmanev, this answer is incorrect. Please see the correct answer by Zvi Tarem

You don't need angular, you can call this function:

function daysRemainingInMonth(date) {
   var year = date.getYear();
   var month = date.getMonth();
   return new Date(year, month, 0).getDate()
}

Edit: Updated now that I know you have the date

Solution 2:[2]

It may be a bit late, but the right answer is a follows:

In order to find the number of days in a month, you need to get the 'date' of the 0th day of the next month:

let daysInMonth = new Date(year, month + 1, 0).getDate();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Zvi Tarem