[英]Converting non-standard date format (e.g., "5 Sep") to dd/mm (e.g., 05/09)
[英]How do i do a format check? so the input is in the correct format. E.g. dd/mm/yy. (Visual Basic)
我早就說過,查看值是否采用正確格式的最佳方法是實際嘗試解析它。 這具有作為完美驗證檢查的優點,而不僅僅是一種啟發式方法,並且為您提供要使用的目標類型的實例,這通常是下一步。
因此我建議DateTime.TryParseExact()
。 這是一個基本示例:
Dim input As String = " ... "
Dim result As DateTime
Dim format = "dd/MM/yyyy"
If DateTime.TryParseExact(input, format, Nothing, Nothing, result) Then
' The input is in the correct format
Else
' The input is NOT in the correct format
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.