vb.net - 如果转换成功,我可以得到条件吗?
问题描述
这是示例:
Dim a As String = "2018-08-08"
Dim b As Date
我可以在 vb.net 中做到这一点吗?这是算法:
If (b=a) is success Then
.........
End If
我希望你知道我的意思
解决方案
这就是类型的TryParse
和TryParseExact
方法的DateTime
用途。他们将尝试将 a 转换String
为 aDateTime
并返回Boolean
表明它是否成功的 a。如果成功,DateTime
则通过声明的参数输出ByRef
,例如
If Date.TryParse(a, b) Then
'The conversion was successful and 'a' contains the Date value.
Else
'The conversion failed and 'a' contains the default value for a Date.
End If
推荐阅读
- python - Python:如何将系统发育树转换为循环格式?
- php - PHP 启动:无法在 Yii2 中加载动态库 '/usr/lib/php/20151012/pgsq
- javascript - axios 获取请求返回错误 UNDEFINED
- ansible - ansible - 使用 ipmath 将 1 添加到 ip 地址变量
- azure - 有没有办法通过 ARM 模板将加密(CMK-客户托管密钥)和 Vnet 集成添加到 Azure 语音服务(认知)
- spring - 一次测试多个 Spring Boot 服务
- spring-mvc - 结合 Spring Integration 和 @ExceptionHandler
- android - OneSignal Android Studio 获取 FCM 令牌时出现未知错误
- javascript - 按钮上的单击事件在 Internet Explorer 中不起作用
- reactjs - 为什么我的状态有时不会改变。是什么原因?