創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買(mǎi)多久送多久,劃算不套路!

本文實(shí)例講述了Java基于正則實(shí)現(xiàn)的日期校驗(yàn)功能。分享給大家供大家參考,具體如下:
private void checkDate() throws IOException {
// 4種分隔符
String sep = "[-\\./_]";
// 年份
String strPattern = "^(19[4-9]\\d|20\\d{2})" + sep;
strPattern += "(";
// 月(1,3,5,7,8,10,12)
strPattern += "((0?[13578]|1[02])" + sep + "(0?[1-9]|[12][0-9]|3[01]))|";
// 月(4,6,9,11)
strPattern += "((0?[469]|11)" + sep + "(0?[1-9]|[12][0-9]|30))|";
// 月(2)
strPattern += "((2)" + sep + "(0?[1-9]|[12]\\d))";
strPattern += ")$";
Pattern p = Pattern.compile(strPattern);
Matcher m = p.matcher("");
int count = 0;
String fileName = ExcelGene.class.getResource("date.txt").getFile();
BufferedReader br = new BufferedReader(new FileReader(fileName));
String line = null;
while ((line = br.readLine()) != null) {
count++;
if (line.trim().length() > 0) {
m.reset(line);
if (!m.find()) {
System.out.println(count + " " + line);
} else {
String year = m.group(1);
String month = m.group(4);
month = month == null ? m.group(7) : month;
month = month == null ? m.group(10) : month;
String date = m.group(5);
date = date == null ? m.group(8) : date;
date = date == null ? m.group(11) : date;
System.out.println(year + "年" + month + "月" + date + "日");
}
}
}
}
分享文章:Java基于正則實(shí)現(xiàn)的日期校驗(yàn)功能示例-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://www.yijiale78.com/article30/csodso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、域名注冊(cè)、小程序開(kāi)發(fā)、商城網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容