基本上我的网上商店有3款产品。每个的细节存储在List aray中。但是
如何计算抵达 ETDA 的Estimated date
(星期六和星期日除外)以了解产品何时到货。
示例:客户订购产品1,下订单的日期是星期四,因此产品1需要3个工作日才能发货,换句话说它将在星期二到货。我将如何在c#中执行此操作,显示用户将在星期二抵达。
答案 0 :(得分:1)
我很想做一个蛮力的方法,只是因为它节省了脑力:
int workingDays = 3;//get from item
DateTime dt = DateTime.Today();
while(workingDays > 0)
{
dt = dt.AddDays(1);
if(dt.DayOfWeek != DayOfWeek.Saturday && dt.DayOfWeek != DayOfWeek.Sunday)
workingDays--;
}
//dt is now the correct day
答案 1 :(得分:1)
您可以使用此方法:
public DateTime DayOfArrival(DateTime startDate, int numberOfWordkingDays )
{
var result = startDate;
var counter = 0;
while (counter < numberOfWordkingDays)
{
if (result.DayOfWeek != DayOfWeek.Saturday && result.DayOfWeek != DayOfWeek.Sunday)
counter++;
result = result.AddDays(1);
}
return result;
}