0
Dim string_date As String 
string_date="31/03/2014"    

如何将 string_date 转换为“dd/MM/yyyy”格式的日期以与当前日期进行比较

4

2 回答 2

1

使用 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
于 2013-11-12T04:50:34.520 回答
0

最后,我得到了自己的解决方案。

d1 as date
string_date as string
string_date="31/03/2014"
d1 = Date.ParseExact(string_date, "dd/MM/yyyy", Globalization.CultureInfo.InvariantCulture)
于 2013-11-14T04:14:49.397 回答