我使用以下代码来计算购买时间
TimeRange timeRange = new TimeRange(
new DateTime(2018, 1, 08, 10, 00, 00),
new DateTime(2018, 1, 15, 15, 30, 00));
CalendarDateDiff dateDiff = new CalendarDateDiff();
dateDiff.WorkingHours.Add(new HourRange(9, 18));
dateDiff.AddWorkingWeekDays();
var calendarDateAdd = new CalendarDateAdd();
calendarDateAdd.ExcludePeriods.Add(new Day(2018, 1, 10,calendarDateAdd.Calendar));
TimeSpan nonBusinessHours = dateDiff.Difference(timeRange.Start, timeRange.End);
double businessHours = timeRange.Duration.TotalHours -nonBusinessHours.TotalHours;
return businessHours;
详细说明在代码项目中。ternary operator。在该代码中,它指定了添加假期的代码。但它没有按照规定正确工作。 此处列出了所需的Nuget包 Calculate-Business-Hours @ codeproject