【发布时间】:2018-02-02 12:29:13
【问题描述】:
用 c# 开发。我有两个 DateTime 对象。我必须从天数中消除周六和周日。假设我有 5 天,包括周六和周日。我想检查周六周日的天数并减少天数。
DateTime startDate = DateTime.ParseExact(startDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
DateTime endDate = DateTime.ParseExact(endDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
TimeSpan diff = endDate - startDate;
days = diff.Days;
我试过了,
How can I calculate the Number of Weekends between two dates
但我无法消除周六周日,因为给定的链接只有在日期差异大于 7 时才会消除周末。还没有我的解决方案。
【问题讨论】:
-
你不包括假期吗?
-
排除意味着如果这一天是假期,我想减少天数