gpt4 book ai didi

.net - 是否有与 Excel 中的 NETWORKDAYS 等效的 .NET 方法?

转载 作者:行者123 更新时间:2023-12-04 22:11:05 25 4
gpt4 key购买 nike

我正在尝试在 Visual Basic 中进行一些日期数学运算。 NETWORKDAYS Excel中的功能正是我所需要的。 .NET 中是否有等效或类似的方法?

最佳答案

看看这个:

private int CountWorkDays( DateTime startDate, DateTime endDate, List<DateTime> excludedDates )
{
int dayCount = 0;
int inc = 1;
bool endDateIsInPast = startDate > endDate;
DateTime tmpDate = startDate;
DateTime finiDate = endDate;

if( endDateIsInPast )
{
// Swap dates around
tmpDate = endDate;
finiDate = startDate;

// Set increment value to -1, so it DayCount decrements rather
// than increments
inc = -1;
}

while( tmpDate <= finiDate )
{
if( !excludedDates.Contains( tmpDate ) )
{
dayCount += inc;
}

// Move onto next day
tmpDate = tmpDate.AddDays( 1 );
}

return dayCount;
}

关于.net - 是否有与 Excel 中的 NETWORKDAYS 等效的 .NET 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1092589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com