package cn.true123.cn;
public class Utils{
/**
*
*/
public static int check_year(String year) {
int thisyear = 0;
if (year == null || year == "") {
return -1;
} else if (year.length() < 4) {
return -2;
} else if (year.length() == 4) {
thisyear = Integer.parseInt(year);
} else if (year.length() == 8) {
thisyear = Integer.parseInt(year.substring(0, 4));
}
if (thisyear % 400 == 0 || (thisyear % 4 == 0 & thisyear % 100 != 0)) {
return 0;
}
return 0;
}
public static boolean check_date(String year) {
int thisyear = 0;
int thismonth = 0;
int thisday = 0;
if (year == null || year == "") {
return false;
} else if (year.length() < 8) {
return false;
}
thisyear = Integer.parseInt(year.substring(0, 4));
thismonth = Integer.parseInt(year.substring(4, 6));
thisday = Integer.parseInt(year.substring(6, 8));
if (thismonth < 1 || thismonth > 12) {
return false;
} else if (thismonth == 1 || thismonth == 3 || thismonth == 5
|| thismonth == 7 || thismonth == 8 || thismonth == 10
|| thismonth == 12) {
if (thisday < 1 || thisday > 31) {
return false;
}
} else {
if (thisday < 1 || thisday > 30) {
return false;
}
}
if (thismonth == 2) {
if (check_year(String.valueOf(thisyear)) == 0) {
if (thisday > 29) {
return false;
}
} else {
if (thisday > 28) {
return false;
}
}
}
return true;
}
}