添加天到日期,但不包括周末 [英] Adding Days to a Date but Excluding Weekends

查看:104
本文介绍了添加天到日期,但不包括周末的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个日期如何添加一个天数,但不包括周末。例如,给定11/12/2008(星期三)和添加五个将导致11/19/2008(星期三),而不是2008年11月17日(星期一)。

Given a date how can I add a number of days to it, but exclude weekends. For example, given 11/12/2008 (Wednesday) and adding five will result in 11/19/2008 (Wednesday) rather than 11/17/2008 (Monday).

我可以这样想度过每一天循环添加和检查,看看它是否是一个周末,一个简单的办法,但我想看看是否有什么更优雅。我也有兴趣在任何F#的解决方案。

I can think of a simple solution like looping through each day to add and checking to see if it is a weekend, but I'd like to see if there is something more elegant. I'd also be interested in any F# solution.

推荐答案

用流利的DateTime https://github.com / FluentDateTime / FluentDateTime

using Fluent DateTime https://github.com/FluentDateTime/FluentDateTime

        var dateTime = DateTime.Now.AddBusinessDays(4);

这篇关于添加天到日期,但不包括周末的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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