添加天到日期,但不包括周末 [英] Adding Days to a Date but Excluding Weekends
问题描述
给定一个日期如何添加一个天数,但不包括周末。例如,给定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屋!