比较日期值 [英] Compare the date value

查看:76
本文介绍了比较日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string date="23-06-1999";





我有这样的约会,现在我的要求是我想要的如果日期是MM-dd-yy格式,检查条件。



如果日期格式相同,请插入记录,否则我想显示错误信息...





任何人都能帮我解决这个问题...



I have a date like this, now my requirement is i want to check the condition if the date is in "MM-dd-yy" format or not.

If the date is in the same format insert the records otherwise i want to display error message...


Can any body help me out of this...

推荐答案





以及 DateTime.TryParseExact ,你可以使用正则表达式。

使用下面的表达式来表示mm-dd- yyyy。

/ ^(0 [1-9] | 1 [012])[/ - 。](0 [1-9] | [12] [0- 9] | 3 [01])[/ - 。](19 | 20)\d\d +
Hi,

along with DateTime.TryParseExact, you can make use of regular expressions.
use below expression for mm-dd-yyyy.
/^(0[1-9]|1[012])[/ -.](0[1-9]|[12][0-9]|3[01])[/ -.](19|20)\d\d+


/



参考文章 30分钟正则表达式教程 [ ^ ]了解更多关于正则表达式。



希望它有所帮助。
/

refer article The 30 Minute Regex Tutorial[^] for more on regular expressions.

hope it helps.


您可以使用DateTime.TryParseExact方法并传递相应的dateformat。如果成功,您可以进行进一步处理。



通过以下MSDN链接获取更多信息。

http://msdn.microsoft.com/en-us/library/ms131044.aspx [ ^ ]



一切顺利。
You can use DateTime.TryParseExact method and pass the appropriate dateformat. If it succeeds you can do your further processing.

Go through the below MSDN link for more info.
http://msdn.microsoft.com/en-us/library/ms131044.aspx[^]

All the best.


这篇关于比较日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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