我正在解决一个问题,问题是你应该从2000年到2011年获得black fridays
的所有列表。那么如何在vb.net
中做到这一点?有什么帮助吗?
答案 0 :(得分:2)
刚刚写了这段代码。在所有条件下测试。希望能帮助到你。祝你好运:)
Dim BlackFridayList As String = ""
Dim dt As Date
Dim weeknumber As Integer = 1
For i = 2000 To 2011
dt = New Date(i, 11, 1)
weeknumber = 1
' find first friday
While dt.DayOfWeek <> DayOfWeek.Friday
dt = dt.AddDays(1)
weeknumber = weeknumber + 1
End While
If weeknumber = 1 And (dt.Day + 28 < Date.DaysInMonth(dt.Year, dt.Month)) Then
' add four weeks
dt = dt.AddDays(28)
Else
' add three weeks
dt = dt.AddDays(21)
End If
BlackFridayList = BlackFridayList & dt.ToLongDateString & vbCrLf
Next
MsgBox(BlackFridayList) 'List of all black fridays
答案 1 :(得分:1)
黑色星期五是11月第四个星期四之后的第二天。您可以使用DateTime函数确定这些年份的日期。
http://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx
答案 2 :(得分:1)
Function BlackFriday(Year as Integer) As DateTime
Dim november1 = New DateTime(Year, 11, 1)
Dim firstThursday = Enumerable.Range(0, 7).Select(Function(x) november1.AddDays(x)).First(Function(x) x.DayOfWeek = DayOfWeek.Thursday)
Return firstThursday.AddDays(22)
End Function
使用它:
Dim blackFridays = Enumerable.Range(2000,12).Select(Function(year) BlackFriday(year)).ToList