我需要找到一种方法来查找我们所在任何一周的星期一的日期(DD / MM / YYYY)。
例如,对于本周,星期一将为09/11/2009,如果是下周,则为16/11/2009。
我设法以代码的形式到达某个地方,但是我所得到的只是“无法转换为整数”错误。我正在使用Date.Today和AddDays()。
谢谢你的帮助。 :)
最佳答案
如果星期天是一周的第一天,则只需执行以下操作:
Dim today As Date = Date.Today
Dim dayDiff As Integer = today.DayOfWeek - DayOfWeek.Monday
Dim monday As Date = today.AddDays(-dayDiff)
如果星期一是一周的第一天:
Dim today As Date = Date.Today
Dim dayIndex As Integer = today.DayOfWeek
If dayIndex < DayOfWeek.Monday Then
dayIndex += 7 'Monday is first day of week, no day of week should have a smaller index
End If
Dim dayDiff As Integer = dayIndex - DayOfWeek.Monday
Dim monday As Date = today.AddDays(-dayDiff)
关于vb.net - 使用VB.NET查找一周中的星期一日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1710487/