Java Utililty Methods Time Different

List of utility methods to do Time Different

Description

The list of methods to do Time Different are organized into topic(s).

Method

intgetTimeDiffMin(String format, String startDate, String endDate)
get Time Diff Min
Date sDate = null;
Date eDate = null;
int ret = 0;
int sign = 1;
try {
    sDate = (new SimpleDateFormat(format)).parse(startDate);
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(sDate);
...
booleanisDateDiff_2(String pattern, String time2, String time1)
is Date Dif_
Date d1 = parse(pattern, time1);
Date d2 = parse(pattern, time2);
long diff = d2.getTime() - d1.getTime();
if (diff > 0) {
    return true;
return false;
BooleanisLowerThanMinTimeDiff(Date lastUpdate, Date now, Long minTimeDiff)
is Lower Than Min Time Diff
long diffinDays = diffInDays(lastUpdate, now);
Boolean resultValue = minTimeDiff < diffinDays;
return resultValue;
LongprintTimeDiff(Long oldDate, Long newDate, String message)
print Time Diff
System.out.println(message + ": " + (newDate - oldDate));
return newDate;
voidprintTimeDiffNano(String message, long start)
print Time Diff Nano
System.out.println(String.format("message: %s duration: %d", message, System.nanoTime() - start));
StringtimeDiff(Calendar calenndarCurrentTime, Calendar calenndarStartTime)
time Diff
long startTime = calenndarStartTime.getTimeInMillis();
long currentTime = calenndarCurrentTime.getTimeInMillis();
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
long elapsed = currentTime - startTime;
return dateFormat.format(new Date(elapsed));
DatetimeDiff(Date salida, Date llegada)
time Diff
long m1 = toMinutes(salida);
long m2 = toMinutes(llegada);
long dif = Math.abs(m2 - m1);
Date fecha = toDate(dif * 60);
return fecha;