如何在javascript中的月代码中编写工作日? [英] how to write working days in month code in javascript?
本文介绍了如何在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/ [
这篇关于如何在javascript中的月代码中编写工作日?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文