Guest User

Untitled

a guest
May 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function daysInMonth(month,year) {
  2. return new Date(year, month, 0).getDate();
  3. }
  4. daysInMonth(7,2009); //31
  5. daysInMonth(2,2009); //28
  6. daysInMonth(2,2008); //29
  7.  
  8. function daysInMonth(Month, Year)
  9. {
  10. return 32 - new Date(Year, Month, 32).getDate();
  11. }
  12.  
  13. daysInMonth(7,2009)
  14. >>> 31
  15.  
  16. Date.prototype.monthDays= function(){
  17. var d= new Date(this.getFullYear(), this.getMonth()+1, 0);
  18. return d.getDate();
  19. }
  20.  
  21. Date.getDaysInMonth(2009, 9)
  22.  
  23. // pass in any date as parameter anyDateInMonth
  24. function daysInMonth(anyDateInMonth) {
  25. return new Date(anyDateInMonth.getYear(),
  26. ++anyDateInMonth.getMonth(),
  27. 0).getDate();}
  28.  
  29. function daysInMonth(month,year) {
  30. return new Date(year, month, 0).getDate();
  31. }
Add Comment
Please, Sign In to add comment