Skip to content
Advertisement

Calculate last day of month

If you provide 0 as the dayValue in Date.setFullYear you get the last day of the previous month:

JavaScript

There is reference to this behaviour at mozilla. Is this a reliable cross-browser feature or should I look at alternative methods?

Advertisement

Answer

JavaScript
JavaScript

Output differences are due to differences in the toString() implementation, not because the dates are different.

Of course, just because the browsers identified above use 0 as the last day of the previous month does not mean they will continue to do so, or that browsers not listed will do so, but it lends credibility to the belief that it should work the same way in every browser.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement