Dim string_date As String
string_date="31/03/2014"
如何将 string_date 转换为“dd/MM/yyyy”格式的日期以与当前日期进行比较
使用 DateTime.TryParseExact():
Dim string_date As String = "31/03/2014"
Dim dt As DateTime
If DateTime.TryParseExact(string_date, "dd/MM/yyyy", Nothing, Globalization.DateTimeStyles.None, dt) Then
Debug.Print("dt = " & dt.ToString("D"))
If dt.Equals(DateTime.Today) Then
Debug.Print("Equal to Today")
Else
Debug.Print("Not Equal to Today")
End If
End If
最后,我得到了自己的解决方案。
d1 as date
string_date as string
string_date="31/03/2014"
d1 = Date.ParseExact(string_date, "dd/MM/yyyy", Globalization.CultureInfo.InvariantCulture)