向日期添加天数但不包括周末 [英] Adding Days to a Date but Excluding Weekends
问题描述
给定一个日期,我如何为其添加天数,但不包括周末.例如,给定 11/12/2008(星期三),加上五个将导致 11/19/2008(星期三)而不是 11/17/2008(星期一).
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.
推荐答案
using Fluent DateTime https://github.com/FluentDateTime/FluentDateTime
using Fluent DateTime https://github.com/FluentDateTime/FluentDateTime
var dateTime = DateTime.Now.AddBusinessDays(4);
这篇关于向日期添加天数但不包括周末的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!