我正在尝试将此 VB 块转换为 C#。
Public Function AddWorkingDays(ByVal DateIn As DateTime, _
ByVal ShiftDate As Integer) As DateTime
Dim b As Integer
Dim datDate As DateTime = DateIn ' Adds the [ShiftDate] number of working days to DateIn'
For b = 1 To ShiftDate
datDate = datDate.AddDays(1)
' Loop around until we get the need non-weekend day'
If Weekday(datDate) = 7 Then
datDate = datDate.AddDays(2)
End If
Next
Return datDate
End Function
到目前为止我有
public DateTime AddWorkingDays(DateTime DateIn, int ShiftDate)
{
int b = 0;
DateTime datDate = DateIn;
// Adds the [ShiftDate] number of working days to DateIn
for (b = 1; b <= ShiftDate; b++)
{
datDate = datDate.AddDays(1);
// Loop around until we get the need non-weekend day
if (DateAndTime.Weekday(datDate) == 7)
{
datDate = datDate.AddDays(2);
}
}
return datDate;
}
我知道 C# DateAndTime 中不存在我只是将它放在 if 语句中以完成代码块。我真正的问题是让 IF 语句起作用。我不确定 DateTime.Now.Weekday 是否与之前的 VB 代码中的语句相同。