进入的一年是否在19世纪 [英] Entered year is in 19th century or not

查看:90
本文介绍了进入的一年是否在19世纪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何检查输入年份是否在19世纪。

我输入20100101(yyyymmdd)格式

在这里,我将进入19世纪后的年份,而不是19世纪之前。

如果我输入00010101这会显示一条消息,我该如何检查。

任何人都可以帮助我,它是紧急的。

Hi,

How can i check enter year is in 19th century or not.
I am entering 20100101(yyyymmdd) format
In this i will enter year after 19th century,not before 19th century.
If am entering 00010101 this it shows a message,how can i check like this.
Can any one help me please,its urgent.

推荐答案

19世纪意味着18010101之后你可以检查strin compare如果它大于18010101它是在18世纪或之后。顺便说一下,你必须检查月和日的情况和日期是否正确。



所以基本方法是DateTime.Parse(yyyyMMdd)如果错了你会得到一个例外如果日期还可以你可以检查它的年份大于1801与否。
19 th century means after 18010101 so you can check strin compare if it bigger than 18010101 it is in or after 18th century. By the way you must check month and day cases and date is correct or not.

So basic method is DateTime.Parse("yyyyMMdd") if it is wrong you will get an exception if date is ok you can check that it's year is greater than 1801 or not.


我建​​议您使用正则表达式 [ ^ ]使用 IsMatch() [ ^ ]方法指示正则表达式构造函数中指定的正则表达式是否找到匹配项在指定的输入字符串中。



您可以在此处找到的模式:正则表达式匹配有效日期 [ ^ ]
I would suggest you to use Regex[^] with IsMatch()[^] method indicates whether the regular expression specified in the Regex constructor finds a match in a specified input string.

The pattern you'll find here: Regular Expression Matching a Valid Date[^]


这篇关于进入的一年是否在19世纪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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