return (sysDate.getTimeInMillis() - failDate.getTimeInMillis()) / (24 * 60 * 60 * 1000);
}
/**
-
取得两个日期相差的自然日
-
@param date1
-
@param date2
-
@return
*/
public static long getDiffNaturalDays(Date date1, Date date2) throws ParseException {
return Math.abs(getDiffNaturalDayNotAbs(date1, date2));
}
/**
-
取得两个日期相差的自然日
-
@param date1
-
@param date2
-
@return
*/
public static long getDiffNaturalDayNotAbs(Date date1, Date date2) throws ParseException {
long diffDays;
DateFormat dateFormat = new SimpleDateFormat(webFormat);
//去掉时分秒
String dateStr1 = dateFormat.format(date1);
String dateStr2 = dateFormat.format(date2);
diffDays = (dateFormat.parse(dateStr1).getTime() - dateFormat.parse(dateStr2).getTime()) / (24 * 60 * 60 * 1000);
return diffDays;
}
public static String getBeforeDayString(String dateString, int days) throws ParseException {
DateFormat df = getNewDateFormat(SHORT_FORMAT);
Date date = df.parse(dateString);
date = new Date(date.getTime() - ONE_DAY_MILL_SECONDS * days);
return df.format(date);
}
public static boolean isValidShortDateFormat(String strDate) {
if (strDate == null || strDate.length() != SHORT_FORMAT.length()) {
return false;
}
try {
// ---- 避免日期中输入非数字 ----
Integer.parseInt(strDate);
} catch (NumberFormatException e) {
return false;
}
DateFormat df = getNewDateFormat(SHORT_FORMAT);
try {
df.parse(strDate);
} catch (ParseException e) {
return false;
}
return true;
}
public static boolean isValidShortDateFormat(String strDate, String delimiter) {
String temp = strDate.replaceAll(delimiter, “”);
return isValidShortDateFormat(temp);
}
/**
-
判断表示时间的字符是否为符合yyyyMMddHHmmss格式
-
@param strDate
-
@return
*/
public static boolean isValidLongDateFormat(String strDate) {
if (strDate.length() != LONG_FORMAT.length()) {
return false;
}
try {
Long.parseLong(strDate); // ---- 避免日期中输入非数字 ----
} catch (Exception NumberFormatException) {
return false;
}
DateFormat df = getNewDateFormat(LONG_FORMAT);
try {
df.parse(strDate);
} catch (ParseException e) {
return false;
}
return true;
}
/**
-
判断表示时间的字符是否为符合yyyyMMddHHmmss格式
-
@param strDate
-
@param delimiter
-
@return
*/<