![](/img/trans.png)
[英]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.