Validate number of days in a given month

前端 未结 13 2363
独厮守ぢ
独厮守ぢ 2021-01-31 18:14

Performance is of the utmost importance on this one guys... This thing needs to be lightning fast!


How would you validate the number of days in a given mont

13条回答
  •  眼角桃花
    2021-01-31 18:32

    function caldays(m,y)
    {
        if (m == 01 || m == 03 || m == 05 || m == 07 || m == 08 || m == 10 || m == 12)
        {
            return 31;              
        }
        else if (m == 04 || m == 06 || m == 09 || m == 11)
        {
            return 30;        
        }
        else
        {    
            if ((y % 4 == 0) || (y % 400 == 0 && y % 100 != 0))
            {    
                return 29;          
            }
            else 
            {
                return 28;              
            }
        }    
    }
    

    source: http://www.dotnetspider.com/resources/20979-Javascript-code-get-number-days-perticuler-month-year.aspx

提交回复
热议问题