如何检查给定值或字符串是否为datetime? [英] How to check give value or string is datetime or not ?

查看:80
本文介绍了如何检查给定值或字符串是否为datetime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
如何在vb中检查给定值或字符串是否为datetime

例如:用户可以给出这样的值100-10-6-1,实际上是100- 10-6-1是序列号,所以如何使用vb在asp.net中检查这是否是日期时间。



Hi How to check given value or string is datetime or not in vb.
E.g:User can give value like this 100-10-6-1,actually "100-10-6-1" is serial no,so how to check this is datetime or not in asp.net using vb.

'Below all not working correctly

 Dim value1 As String = "100-10-6-1"
 Dim inta As DateTime
 If (Not DateTime.TryParse(value1, inta)) Then
 ShowMessage("This is not date field !")
 Exit Sub
 End If
'--------------------------------------
  Dim value1 As String = "100-10-6-1" 'Here if give "11-11-11" also goes else part
 If stringSplit(inti).[GetType]() Is GetType(DateTime) Then
  ShowMessage("This is  date field !")
  Else
  ShowMessage("This is not date field !")
 End If





我尝试过:



http://stackoverflow.com/questions/3998685/how-to-determine-if-an-object-is-a-datetime-in-vb-net



我试试这个链接,但是显示错误

http://prntscr.com/a4rwsk









问候

Aravind



What I have tried:

http://stackoverflow.com/questions/3998685/how-to-determine-if-an-object-is-a-datetime-in-vb-net

I try this link ,but it show error
http://prntscr.com/a4rwsk




Regards
Aravind

推荐答案

Stack Overflow解决方案不适合您,因为您的数据类型无论如何都是字符串。您应该确定这样的字符串是否是 DataTime 值的有效表示。 Fopr的目的是你可以使用 DateTime.TryParse方法(系统) [ ^ ]或日期时间.TryParseExact方法(系统) [ ^ ]。
The Stack Overflow solution doesn't work for you, because your data type is anyway a string. You should establish if such a string is a valid representation of a DataTime value. Fopr the purpose you may use either the DateTime.TryParse Method (System)[^] or DateTime.TryParseExact Method (System)[^].


这篇关于如何检查给定值或字符串是否为datetime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆