得到下一个工作日 [英] get next working day

查看:72
本文介绍了得到下一个工作日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问在C#中获得下一个工作日的方式是什么?
我想传递一个日期,如果传递的日期是星期五,则返回星期一,如果传递的日期是星期二,则返回日期是星期三,依此类推.因此,它应该在下一个工作日返回.我是否只需添加if语句即可获取返回值?
谢谢

What is the way to get the next working day in c# please?
I would like to pass in a date and if the passed in date is friday then it returns monday, if passed in date is tuesday then return date is wednesday and so forth. So it should return the next working day. Do I just have to add if statements to get the return value?
Thanks

推荐答案

看看此CP文章:业务日期计算 [ ^ ].
Have a look at this CP article: Business Dates Calculation[^].


业务日期计算 [ [
Business Dates Calculation[^] is a article that should surely help you out.

If not, this[^] would be another good read.


public DateTime FindBusinessDay(1, DateTime fromDate)
       {
           //This is used to count the number of business days

           int businessDays = 0;

           int noOfDays = numberOfBusinessDays;

           for (int i = 1; i <= numberOfBusinessDays; i++)
           {
               if (IsWeekEnd(fromDate))
                   numberOfBusinessDays++;
               else
                   businessDays++;
               if (businessDays != noOfDays)
               {
                   fromDate = fromDate.AddDays(1);
               }

               else
               {
                   break;
               }
           }

           return fromDate;
       }




它将返回您可以获取日期的日期




It will return date from that you can get day


这篇关于得到下一个工作日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆