如何在javascript中的月代码中编写工作日?

问题描述:


如何在javascript中按月编写工作日代码?
请解决我的问题plzzzzzzzzzzzzzzzz.

Hi,
how to write working days in month code in javascript?
please solve my problem plzzzzzzzzzzzzzz.

如果没有大量外部信息,您将无法准确.

要计算基本工作日计数(无节假日,仅假设星期一至星期五):
You can''t accurately, without a lot of external information.

To calculate the basic working days count (without holidays, and assuming Monday to Friday only):
function getDaysInMonth(iMonth, iYear)
    {
    return 32 - new Date(iYear, iMonth, 32).getDate();
    }

function isWorkDay(year, month, day) 
    {
    var dayOfWeek = new Date(year, month, day).getDay();
    return dayOfWeek >=1 && day <=5; // Sun = 0, Mon = 1, and so forth
    }

function getWorkDays(month, year)
    {
    var days = getDaysInMonth(month, year);
    var workdays = 0;
    for(var i = 0; i < days; i++) 
        {
        if (isWorkDay(year, month, i+1)) 
            {
            workdays++;
            }
        }
    return workdays;
    }


问题是,这不能给您准确的计数-您还需要考虑假期,解决这些问题要困难得多,并且会因地区而异.


The problem is that that does not give you an accurate count - you also need to allow for holidays, and working those out is a lot harder, and will vary from region to region.


http://snipplr.com/view/4086/ [