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

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

问题描述

给我一​​个日期,如何添加几天,但不包括周末。例如,由于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.

推荐答案

使用Fluent DateTime https://github.com/FluentDateTime/FluentDateTime

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

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

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

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