Java Utililty Methods Date Difference

List of utility methods to do Date Difference

Description

The list of methods to do Date Difference are organized into topic(s).

Method

DateparseParamDate(final String diff)
parse a string to get absolute date
final String dateString = "0000-01-01T00:00:00.000UTC";
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ");
final char[] dateChars = dateString.toCharArray();
String timeZone = "UTC";
final String[] units = diff.split("[.]");
for (final String unit : units) {
    if (unit.matches("[YMDhms][0-9]+") || unit.matches("[Z]...")) {
        final char unitdesc = unit.charAt(0);
...
longtimeDiff(Calendar date1, Calendar date2)
time Diff
long diff = date1.getTimeInMillis() - date2.getTimeInMillis();
return diff;
StringtimeDiffHourMinSec(Date start, Date end)
time Diff Hour Min Sec
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(start);
long startTime = calendar.getTimeInMillis();
calendar.setTime(end);
long endTime = calendar.getTimeInMillis();
long diff = endTime - startTime;
long seconds = (diff / 1000) % 60;
long minutes = (diff / (60 * 1000)) % 60;
...