开发者

isDate control on european data in vb.net

How can i do a isDate() control开发者_高级运维 on a date like 16/01/2008 in vb.net?


To check if 16/01/2008 is a valid date, you do:

Dim result As Date
If Date.TryParse("16/01/2008", result) Then
     'The date is valid '
End If

Now this will use the current culture set. If you want to validate it against a specific culture, you can do it like this (example with french culture):

If Date.TryParse("16/01/2008", Globalization.CultureInfo.GetCultureInfo("fr-FR"), _
                 Globalization.DateTimeStyles.None, result) Then
    'The date is valid '
End If


If the date format in your input data is fixed to month/day/year and does not depend on the current culture, you should use DateTime.TryParseExact:

Public Shared Function IsValidInputDate(ByVal str As String) As Boolean
    Dim dt as DateTime
    Return DateTime.TryParseExact(str, "d/M/yyyy", Nothing, Globalization.DateTimeStyles.None, dt)
End Function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜