如何确定最后一个营业日在某一个月? [英] How to determine the last business day in a given month?
本文介绍了如何确定最后一个营业日在某一个月?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何计算在.NET月份的最后一个营业日?
How can I calculate the last business day of the month in .NET?
推荐答案
我会做这样的周一至周五商业周刊:
I would do it like this for a Monday through Friday business week:
var holidays = new List<DateTime>{/* list of observed holidays */};
DateTime lastBusinessDay = new DateTime();
var i = DateTime.DaysInMonth(year, month);
while (i > 0)
{
var dtCurrent = new DateTime(year, month, i);
if(dtCurrent.DayOfWeek < DayOfWeek.Saturday && dtCurrent.DayOfWeek > DayOfWeek.Sunday &&
!holidays.Contains(dtCurrent))
{
lastBusinessDay = dtCurrent;
i = 0;
}
else
{
i = i - 1;
}
}
这篇关于如何确定最后一个营业日在某一个月?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文