java通用的方法整理
判斷字符串是否為空
public static boolean IsEmpty(String str){ if (str == null){ return true; } if ("".equals(str)){ return true; } return false; }
判斷字符串str是否包含s1
public static boolean IsHas(String str,String s1){ if(IsEmpty(str)){ return false; } if(IsEmpty(s1)){ return false; } if(str.indexOf(s1) == -1){ return false; } return true; }
判斷l(xiāng)ist 是否為空
public static boolean IsEmptyList(List lt){ if (lt == null){ return true; } if (lt.size() == 0){ return true; } return false; }
判斷字符串是否相等
public static boolean Equals(String str1,String str2){ if(IsEmpty(str1)){ if(IsEmpty(str2)){ return true; }else{ return false; } } if (str1.equals(str2)){ return true; } return false; }
倆個日期間隔的天數(shù)
public static long MakeDateLength(String Date1, String Date2){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try{ Date d1 = df.parse(Date1); Date d2 = df.parse(Date2); long t1 = d1.getTime(); long t2 = d2.getTime(); long t = t1 - t2; t /= 1000*60*60*24; return t; } catch (ParseException e){ } return 0; }
通過給定日期推算新的日期,afterDay為經(jīng)過的天數(shù)
public static String GetDateAfter(String date,int afterDay){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try{ Date d = df.parse(date); long nTime = d.getTime(); long aTime = ((long) afterDay) * 24 * 60 * 60 * 1000; d.setTime(nTime + aTime); return df.format(d); } catch (ParseException e){ } return ""; }
浙公網(wǎng)安備 33010602011771號