List of utility methods to do Date Difference
int | getDifference(Date a, Date b) get Difference int tempDifference = 0; int difference = 0; Calendar earlier = Calendar.getInstance(); Calendar later = Calendar.getInstance(); if (a.compareTo(b) < 0) { earlier.setTime(a); later.setTime(b); } else { ... |
long | getDifference(String dateStr1, String dateStr2, char choice) Gets the difference between 2 dates in Seconds or Minutes or Hours or Days based on the choice given. if (dateStr1 == null || dateStr2 == null) throw new RuntimeException("Invalid Input"); DateFormat df = new SimpleDateFormat(STANDARD_DATE_FORMAT_STRING); Date date1 = null, date2 = null; try { date1 = df.parse(dateStr1); } catch (ParseException e) { e.printStackTrace(); ... |
long | getDifferenceInDays(Calendar calendar0, Calendar calendar1) get Difference In Days return getDifferenceInDays(calendar0.getTimeInMillis(), calendar1.getTimeInMillis());
|
String | getDiffMon(Date dt, int idiff) get Diff Mon Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.MONTH, idiff);
return dtSimpleFormat(c.getTime());
|
String | getDiffMon(Date dt, int idiff) get Diff Mon Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.MONTH, idiff);
return dateFormat(c.getTime());
|
String | getDiffToString(Date date, int n, String pattern) get Diff To String Date returnDay = new Date(date.getTime() + n * 24 * 3600 * 1000L); SimpleDateFormat df = new SimpleDateFormat(pattern); return df.format(returnDay); |
String | getScoreDifferenceString(int newNumber, int oldNumber) get Score Difference String DecimalFormat format = new DecimalFormat("+#;-#"); return format.format(newNumber - oldNumber); |
long | getSecondDiff(Date d1, Date d2) get Second Diff long d1t = d1.getTime(); long d2t = d2.getTime(); return (d2t - d1t) / 1000; |
double | getTimeDifferenceInSeconds(Date d, Date d2) get Time Difference In Seconds return Math.abs(d.getTime() - d2.getTime()) / 1000.0;
|
Date | nextSeconds(Date date, int diff) next Seconds return add(date, Calendar.SECOND, diff);
|