vb.net中比较两个日期是否相等
我有一个日期变量startdt
和一个字符串变量hdnsdate
。
假设 startdt
具有 3/1/2012 形式的值,并且 hdnsdate
具有 03/01/ 形式的值2012 年。我如何比较这两个日期在 vb.net 中是否相等。
在我的程序的 if
条件下,我想进行此检查。如果两个日期匹配,则移出 if
循环,否则进入 if
循环。
例如,C# 中的示例正是我想要的。
if(startdt !=hdnsdate)
{
//Do
}
else
{
//Do this
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Parse、ParseExact 方法将
hdnsdate
(字符串)解析为 Date 类型,并使用 DateTime.Compare、Equals
、CompareTo
方法。字符串到日期
比较日期的替代方法:
Parse
hdnsdate
(string) to Date type using Parse, ParseExact method and use DateTime.Compare,Equals
,CompareTo
methods.String to date
Alternative to compare date:
您需要将字符串解析为
DateTime
然后比较两者。VB.NET
C#:
我建议查看
DateTime
上定义的不同解析方法,因为您可能需要使用 标准 或 自定义日期和时间格式字符串,以确保正确解析字符串。You need to parse the string into a
DateTime
then compare the two.VB.NET
C#:
I suggest looking at the different parsing methods defined on
DateTime
, as you may need to use a standard or custom date and time format string to ensure the string gets parsed correctly.