日期格式错误无效

时间:2014-10-17 22:28:36

标签: vb.net syntax-error date-formatting

我有这个功能:

Public Function checkstring(ByVal AnyDateString As Date) As Date    

    Dim ResDate As String    
    Dim Yr As String    
    Dim Mt As String    
    Dim Dt As String    
    Dim format As String    
    Dim provider As System.Globalization.CultureInfo = System.Globalization.CultureInfo.InvariantCulture    

    Yr = Year(AnyDateString)    
    Mt = Month(AnyDateString)    
    Dt = Microsoft.VisualBasic.DateAndTime.Day(AnyDateString)    

    ResDate = Mt & "/" & Dt & "/" & Yr    
    format = "MM/dd/yyyy"    
    checkstring = Date.ParseExact(DateString, format, provider)    

End Function     

当我运行它时显示此错误:

  

字符串未被识别为有效的DateTime

我确实需要将ResDate字符串存储为格式为MM/dd/yyyy的日期。

0 个答案:

没有答案