List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatDuration
public static String formatDuration(long durationMillis, String format, boolean padWithZeros)
Formats the time gap as a string, using the specified format.
From source file:org.kuali.student.enrollment.class2.courseoffering.service.impl.ManageSOCViewHelperServiceImpl.java
/** * This calculates the time difference for display. Generates a time difference string in the format hh:mm * * @param dateOne end time/*from w w w . j a v a 2s . com*/ * @param dateTwo start time * @param roundUpMinute whether or not to round up the time difference to the nearest minute * * @return formatted date String (hh:mm) */ protected String getTimeDiffUI(Date dateOne, Date dateTwo, boolean roundUpMinute) { if (LOG.isDebugEnabled()) { LOG.debug("Get time difference between {} and {} with roundUpMinute={}", dateOne, dateTwo, roundUpMinute); } Long millisDuration = dateOne.getTime() - dateTwo.getTime(); if (roundUpMinute) { // check the difference between the two dates as milliseconds, and round up to the nearest minute // if dividing by one minute results in a remainder, then round up to the next minute if (millisDuration % ManageSocConstants.ONE_MINUTE_IN_MILLIS != 0l) { Long difference = ManageSocConstants.ONE_MINUTE_IN_MILLIS - (millisDuration % ManageSocConstants.ONE_MINUTE_IN_MILLIS); millisDuration += difference; } } return DurationFormatUtils.formatDuration(millisDuration, ManageSocConstants.SCHEDULE_DURATION_TIME_FORMAT, true); }