1.去除空白(包括全角和半角空格)
public static String trim(String target) {
if (target == null) {
return target;
} else {
return target.trim().replaceAll("^[\\s ]+", "").replaceAll("[\\s ]+$","");
}
}
2. null 或空白判断
public static boolean isBlank(String target) {
return (target == null) || (trim(target).length() == 0);
}
3.判断某日期字符串是否是 yyyyMMdd_HHmmss格式
public static boolean isDateTime(String dataTime) {
boolean result = true;
if (dataTime == null || "yyyyMMdd_HHmmss".length() != dataTime.length()) {
result = false;
} else {
DateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
format.setLenient(false);
try {
format.parse(dataTime);
} catch (ParseException e) {
result = false;
}
}
return result;
}