Imports System.Globalization
Public Sub CheckComputerPurchaseLastWeek()
Dim purchaseRecords As List(Of Dictionary(Of String, Object)) = New List(Of Dictionary(Of String, Object))() From {
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 8, 29)}, },
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 8, 30)}, },
New Dictionary(Of String, Object) From {{"product", "电脑"}, {"purchaseDate", New DateTime(2023, 9, 5)}, }
}
Dim currentDate As
DateTime
= DateTime.Now
Dim lastWeekStart As
DateTime
= currentDate.AddDays(-7).Date.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)
Dim hasPurchase As
Boolean
= False
For Each record
In purchaseRecords
If record("purchaseDate").ToString("MM/dd/yyyy", CultureInfo.InvariantCulture) >= lastWeekStart Then
hasPurchase
= True
Exit For
End If
Next
If hasPurchase Then
Console.WriteLine("上周有购买电脑")
Else
Console.WriteLine("上周没有购买电脑")
End If
End Sub