如何在vb中将日历用于较低的时间格式?
我试图实现的目标:如果较低的日期是星期六和星期日,则将其替换为同一周的星期五(如果日期 = 2012-04-21 或 2012-04-22,则日期 = 2012-04-20)。
2012-04-20T18:26:43
提前致谢
如何在vb中将日历用于较低的时间格式?
我试图实现的目标:如果较低的日期是星期六和星期日,则将其替换为同一周的星期五(如果日期 = 2012-04-21 或 2012-04-22,则日期 = 2012-04-20)。
2012-04-20T18:26:43
提前致谢
只需将一些代码放在一起,无需太多测试。
Sub Main
Dim dt as DateTime = FindDate(Convert.ToDateTime("2012-04-21T18:26:43"))
System.Diagnostics.Debug.WriteLine(dt.ToShortDateTime())
End Sub
Public Function FindDate(ByVal inDate as DateTime) as DateTime
if (inDate.DayOfWeek = DayOfWeek.Saturday Or inDate.DayOfWeek = DayOfWeek.Sunday) then
while (inDate.DayOfWeek <> DayOfWeek.Friday)
inDate = inDate.AddDays(-1)
end while
end if
return inDate
End Function
Public Shared Function NoWeekend(ByVal day As DateTime) As DateTime
If day.DayOfWeek = DayOfWeek.Sunday Then Return day.AddDays(-2)
If day.DayOfWeek = DayOfWeek.Saturday Then Return day.AddDays(-1)
Return day
End Function