判断日期格式
来源:互联网 发布:xampp apache无法启动 编辑:程序博客网 时间:2024/04/28 11:51
package untitled9;
import java.io.*;
import oracle.sql.CHAR;
import java.util.List;
import java.util.ArrayList;
/**
* <p>Title: CheckDate</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: New Modern Technology</p>
* @author Nick Yu
* @version $Id:$
*/
/*
* 判断日期格式, 把你所要Check的日期中间符代替代码中“-”即可,
*/
public class CheckDate
{
public boolean isDigitStr(String str)
{
System.out.println("str="+str);
if(str.length()<8 || str.length()>10)
{
return false;
}
String thefirstyear=String.valueOf(str.charAt(0));
String cYear = str.substring(0,4);
String cFirstSpilt=String.valueOf(str.charAt(4));
String cMonthfirst=String.valueOf(str.charAt(5));
String cMonthorSpilt=String.valueOf(str.charAt(6));
String cMonthorSpilt1=String.valueOf(str.charAt(7));
StringBuffer laststr = new StringBuffer("");
String [] month=split(str,"-");
if(thefirstyear.equals("0")){
return false;
}
for (int j = 0; j < cYear.length(); j++) {
if (!(cYear.charAt(j) >= 48 && cYear.charAt(j) <= 57)){
return false;
}
}
if(!"-".equals(cFirstSpilt)){
return false;
}
if (!(cMonthfirst.charAt(0) >= 48 && cMonthfirst.charAt(0) <= 57)) {
return false;
}
else if(cMonthfirst.endsWith("0") && !(cMonthorSpilt.charAt(0) >= 48 && cMonthorSpilt.charAt(0) <= 57)){
return false;
}
if(!(cMonthorSpilt.charAt(0) >= 48 && cMonthorSpilt.charAt(0) <= 57) && !cMonthorSpilt.equals("-")){
return false;
}
if(cMonthorSpilt.equals("-")){
for(int i=7;i<str.length();i++){
laststr.append(str.charAt(i));
}
}
if(cMonthorSpilt1.equals("-")) {
for(int i=8;i<str.length();i++){
laststr.append(str.charAt(i));
}
}
if(laststr.toString().length()==1) {
if(laststr.toString().equals("0")){
return false;
}
}
if(laststr.toString().length()==2) {
if(laststr.toString().equals("00")){
return false;
}
}
for (int j = 0; j < laststr.toString().length(); j++) {
if (!(laststr.toString().charAt(j) >= 48 && laststr.toString().charAt(j) <= 57)) {
return false;
}
}
if(Integer.parseInt(laststr.toString())>31){
return false;
}
if(month[1].equals("0")||month[1].equals("00")) {
return false;
}
else if(Integer.parseInt(month[1])>12){
return false;
}
if(Integer.parseInt(month[1])==2) {
if(Integer.parseInt(laststr.toString())>29){
return false;
}
}
return true;
}
public static String[] split(String value, String spliter) {
if (value == null || value.equals("")) {
return null;
}
List temp = new ArrayList();
int left = 0;
int index = 0;
int len = value.length();
while (index < len) {
index = value.indexOf(spliter, left);
if (index < 0) {
index = len;
}
temp.add(value.substring(left, index));
left = index + 1;
}
Object[] tmpResult = temp.toArray();
String[] result = new String[tmpResult.length];
for (int i = 0; i < tmpResult.length; i++) {
result[i] = tmpResult[i].toString();
}
return result;
}
public static void main(String[] args) {
CheckDate cd = new CheckDate();
System.out.println(cd.isDigitStr("1007-1-30"));
}
}
import java.io.*;
import oracle.sql.CHAR;
import java.util.List;
import java.util.ArrayList;
/**
* <p>Title: CheckDate</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: New Modern Technology</p>
* @author Nick Yu
* @version $Id:$
*/
/*
* 判断日期格式, 把你所要Check的日期中间符代替代码中“-”即可,
*/
public class CheckDate
{
public boolean isDigitStr(String str)
{
System.out.println("str="+str);
if(str.length()<8 || str.length()>10)
{
return false;
}
String thefirstyear=String.valueOf(str.charAt(0));
String cYear = str.substring(0,4);
String cFirstSpilt=String.valueOf(str.charAt(4));
String cMonthfirst=String.valueOf(str.charAt(5));
String cMonthorSpilt=String.valueOf(str.charAt(6));
String cMonthorSpilt1=String.valueOf(str.charAt(7));
StringBuffer laststr = new StringBuffer("");
String [] month=split(str,"-");
if(thefirstyear.equals("0")){
return false;
}
for (int j = 0; j < cYear.length(); j++) {
if (!(cYear.charAt(j) >= 48 && cYear.charAt(j) <= 57)){
return false;
}
}
if(!"-".equals(cFirstSpilt)){
return false;
}
if (!(cMonthfirst.charAt(0) >= 48 && cMonthfirst.charAt(0) <= 57)) {
return false;
}
else if(cMonthfirst.endsWith("0") && !(cMonthorSpilt.charAt(0) >= 48 && cMonthorSpilt.charAt(0) <= 57)){
return false;
}
if(!(cMonthorSpilt.charAt(0) >= 48 && cMonthorSpilt.charAt(0) <= 57) && !cMonthorSpilt.equals("-")){
return false;
}
if(cMonthorSpilt.equals("-")){
for(int i=7;i<str.length();i++){
laststr.append(str.charAt(i));
}
}
if(cMonthorSpilt1.equals("-")) {
for(int i=8;i<str.length();i++){
laststr.append(str.charAt(i));
}
}
if(laststr.toString().length()==1) {
if(laststr.toString().equals("0")){
return false;
}
}
if(laststr.toString().length()==2) {
if(laststr.toString().equals("00")){
return false;
}
}
for (int j = 0; j < laststr.toString().length(); j++) {
if (!(laststr.toString().charAt(j) >= 48 && laststr.toString().charAt(j) <= 57)) {
return false;
}
}
if(Integer.parseInt(laststr.toString())>31){
return false;
}
if(month[1].equals("0")||month[1].equals("00")) {
return false;
}
else if(Integer.parseInt(month[1])>12){
return false;
}
if(Integer.parseInt(month[1])==2) {
if(Integer.parseInt(laststr.toString())>29){
return false;
}
}
return true;
}
public static String[] split(String value, String spliter) {
if (value == null || value.equals("")) {
return null;
}
List temp = new ArrayList();
int left = 0;
int index = 0;
int len = value.length();
while (index < len) {
index = value.indexOf(spliter, left);
if (index < 0) {
index = len;
}
temp.add(value.substring(left, index));
left = index + 1;
}
Object[] tmpResult = temp.toArray();
String[] result = new String[tmpResult.length];
for (int i = 0; i < tmpResult.length; i++) {
result[i] = tmpResult[i].toString();
}
return result;
}
public static void main(String[] args) {
CheckDate cd = new CheckDate();
System.out.println(cd.isDigitStr("1007-1-30"));
}
}
- 判断日期格式
- 日期Date格式判断
- js判断日期格式
- js判断日期格式
- JS日期格式判断
- JS日期格式判断
- JS日期格式判断
- PHP判断日期格式
- 判断日期格式
- PHP 判断日期格式
- 判断日期格式是否正确。
- 正则表达式判断日期格式
- C#判断输入日期格式
- TextBox文本框判断日期格式
- JS判断日期格式是否合法
- java中判断日期格式
- 正则表达式判断日期格式
- 判断字符串是不是日期格式
- 从梦中醒来
- 学习队列、栈的经典案例--Re:停车场管理模拟修改版
- 成长的烦恼
- SourceForge2007社区选择奖评选结果:FireBird赢得双奖!
- MD5算法加密
- 判断日期格式
- Java Servlet基本方法介绍
- VC中断点失效问题
- Valgrind reports memory leaking in pthread_create()
- SAP系统开发与ABAP的一些概念
- 软件开发人员都应该读的一些书籍
- SQA到底应该做一些什么1---培训的故事2
- 十句职场不败的经典名言
- Linkfields to detail must be unique的意思