code_junkie

What is the best way to determine the number of days in a month with javascript?

Nov 12th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. function daysInMonth(iMonth, iYear) {
  2. return 32 - new Date(iYear, iMonth, 32).getDate();
  3. }
  4.  
  5. function daysInMonth(month,year)
  6. {
  7. return new Date(year, month, 0).getDate();
  8. }
  9.  
  10. var daysInMonth = (function() {
  11. var cache = {};
  12. return function(month,year) {
  13. var entry = year+"-"+month;
  14. if (entry in cache)
  15. return cache[entry];
  16. return cache[entry] = new Date(year, month, 0).getDate();
  17. }
  18. })();
Add Comment
Please, Sign In to add comment