问题描述
我只想知道如何在不包括周末的情况下计算DateTime(当前是图书馆系统).图书馆在周末不开放,这就是为什么我需要计算不包括周末的日期的原因.前任. 15年3月13日=星期五,我直接借了5天.因此,返回日期应为03/20/15 =星期五(因为我没有包括周末) 您能告诉我还是给我一些想法?谢谢!
I just want to know on how to compute DateTime without including weekends (currently making a library system). The library is not open during weekends that is why i need to calculate the date that will not include weekends. Ex. 03/13/15 = friday and im borrowing it for 5 days. So, the return date should be in 03/20/15= friday( because i didnt include the weekends) Can you please tell me or give me some ideas? Thanks!
(当我键入数字时,程序突然冻结)
( The program suddenly freezes when i type a number)
int days = 0;
DateTime deyt = DateTime.Now;
rd.Text = deyt.ToString("MM/dd/yy");
DateTime dt = deyt.AddDays(int.Parse(textBox3.Text));
DateTime span = deyt;
while (span < dt.AddDays(1))
{
if (span.DayOfWeek != DayOfWeek.Saturday && span.DayOfWeek != DayOfWeek.Sunday)
{
days++;
span = span.AddDays(1);
bd.Text = days.ToString("MM/dd/yy");
}
}
推荐答案
如果您有DateTimes列表,则可以过滤出周末日期:
If you have a list of DateTimes you can filter out the weekend dates:
public static List<DateTime> GetDatesWithoutWeekends(List<DateTime> dates)
{
return
dates.Where(date => (date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday))
.ToList();
}
这篇关于不包括约会时间中的周末的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!