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

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

问题描述

给定一个日期,我如何为其添加天数,但不包括周末.例如,给定 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屋!

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