如何计算不包括星期日的一个月的工作日数? [英] how to calculate no of workingdays in month excluding Sundays ?
本文介绍了如何计算不包括星期日的一个月的工作日数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何计算一个月(星期日除外)中的工作日数?
谢谢与问候
Hari
解决方案
我认为这对您有帮助
int year = 2011 ; int month = 11 ; int daysInMonth = 0 ; int days = DateTime.DaysInMonth(year,month); for ( int i = 1 ; i < =天; i ++) { DateTime日= 新 DateTime(年,月,i); 如果(day.DayOfWeek!= DayOfWeek.Sunday) { daysInMonth ++; } }
计算一年中的每个月,请尝试此
int year = 2011 ; int monthsInYear = 12 ; List< int> workDaysEveryMonth = 新 List< int>(); for ( int month = 1 ; month < = monthsInYear; month ++) { int daysInMonth = 0 ; int days = DateTime.DaysInMonth(year,month); for ( int day = 1 ; day < =天;天++) { DateTime currentDay = 新 DateTime(年,月,日); 如果(currentDay.DayOfWeek!= DayOfWeek.Sunday) { daysInMonth ++; } } workDaysEveryMonth.Add(daysInMonth); }
然后您可以使用类似这样的内容显示结果,例如
字符串 []月= {" ," , 3月", 4月", 可以", 6月", " ," 八月", 9月"," ," ," }; 今天的DateTime = DateTime.Now; Label1.Text = " + workDaysEveryMonth [today.Month-" 工作日以" +月[today.Month- 1 ];
^ ]
这可能对您有帮助
http: //stackstackflow.com/questions/4331583/to-calculate-no-of-working-days-in-a-current-month-excepting-sunday-in-windows-a [ 解决方案
I think this will help you
int year = 2011; int month = 11; int daysInMonth = 0; int days = DateTime.DaysInMonth(year, month); for (int i = 1; i <= days; i++) { DateTime day = new DateTime(year, month, i); if (day.DayOfWeek != DayOfWeek.Sunday) { daysInMonth++; } }
to calculate for every month in a year try this
int year = 2011; int monthsInYear = 12; List<int> workDaysEveryMonth = new List<int>(); for (int month = 1; month <= monthsInYear; month++) { int daysInMonth = 0; int days = DateTime.DaysInMonth(year, month); for (int day = 1; day <= days; day++) { DateTime currentDay = new DateTime(year, month, day); if (currentDay.DayOfWeek != DayOfWeek.Sunday) { daysInMonth++; } } workDaysEveryMonth.Add(daysInMonth); }
you could then display the results using something like this e.g.
string[] months = { "January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October","November", "December" }; DateTime today = DateTime.Now; Label1.Text = "There are " + workDaysEveryMonth[today.Month - 1] + " work days in " + months[today.Month - 1];
How-to-get-business-working-day-month[^]
This may help you
http://stackoverflow.com/questions/4331583/to-calculate-no-of-working-days-in-a-current-month-excluding-sunday-in-windows-a[^]
这篇关于如何计算不包括星期日的一个月的工作日数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文