/**
* 計算兩個日期直接相差毫秒
* @param time
* @param pattern
* return Boolean true:經過,fales:不經過
*/
public static boolean isThisTime(long time,String pattern) {
Date date = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String param = sdf.format(date);//參數時間
String now = sdf.format(new Date());//當前時間
if(param.equals(now)){
return true;
}
return false;
}
/**
*距離當前時間88天以內的日期
* @param time
* type:1--88天以內的
* @return
*/
public static boolean getDayDiffFromToday(String time) throws ParseException {
//將字符串轉爲日期
//time=20171210144833 -->要對應"yyyyMMddHHmmss"否則會報unparase
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss"); Date param = sdf.parse(time);//參數時間 long s1=param.getTime();//將時間轉爲毫秒 long s2=System.currentTimeMillis();//獲得當前的毫秒 int day= Math.toIntExact((s2 - s1) / 1000 / 60 / 60 / 24); if (day > 0 && day <= 88){ return true; } return false;}