Commit 527b0d5f by 向延琳

时长格式化

1 parent 73c8147c
...@@ -136,30 +136,10 @@ public class JourneyService { ...@@ -136,30 +136,10 @@ public class JourneyService {
log.info("journeyDetailExportList size()大小===" + journeyDetailExportList.size()); log.info("journeyDetailExportList size()大小===" + journeyDetailExportList.size());
return journeyDetailExportList.stream() return journeyDetailExportList.stream()
.filter(e -> StringUtils.isNotEmpty(e.getJourneyStartTime()) && StringUtils.isNotEmpty(e.getJourneyEndTime())) .filter(e -> StringUtils.isNotEmpty(e.getJourneyStartTime()) && StringUtils.isNotEmpty(e.getJourneyEndTime()))
.peek(e -> e.setDurationStr(DateUtil.getDistanceTime(e.getJourneyStartTime(), e.getJourneyEndTime()))) .peek(e -> e.setDurationStr(DateUtil.getDistanceTimeIgnoreZero(e.getJourneyStartTime(), e.getJourneyEndTime())))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* 时间戳格式化为时,分,秒
*
* @param duration 时间戳差
* @return
*/
protected String normalFormatDuration(long duration) {
if (duration == 0L) {
return "0 秒";
}
//小于0不合法
if (duration < 0L) {
return "";
}
if (duration < org.apache.commons.lang.time.DateUtils.MILLIS_IN_HOUR) {
return DurationFormatUtils.formatDuration(duration, "mm 分 ss 秒");
}
return DurationFormatUtils.formatDuration(duration, "HH 时 mm 分 ss 秒");
}
public Integer countJourneyDetailList(JourneyDetailSearch journeyDetailSearch) { public Integer countJourneyDetailList(JourneyDetailSearch journeyDetailSearch) {
if (journeyDetailSearch.getOrgId() != null) { if (journeyDetailSearch.getOrgId() != null) {
journeyDetailSearch.setCheckedOrgIds(Lists.newArrayList(journeyDetailSearch.getOrgId())); journeyDetailSearch.setCheckedOrgIds(Lists.newArrayList(journeyDetailSearch.getOrgId()));
......
...@@ -1174,6 +1174,52 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils { ...@@ -1174,6 +1174,52 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
} }
/** /**
* 两个时间相差距离多少天多少小时多少分多少秒
*
* @param str1 时间参数 1 格式:1990-01-01 12:00:00
* @param str2 时间参数 2 格式:2009-01-01 12:00:00
* @return String 返回值为:xx天xx小时xx分xx秒
*/
public static String getDistanceTimeIgnoreZero(String str1, String str2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date one;
Date two;
try {
one = df.parse(str1);
two = df.parse(str2);
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
long day = diff / (24 * 60 * 60 * 1000);
long hour = (diff / (60 * 60 * 1000) - day * 24);
long min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
long sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
return getIgnoreZero(day, "天") +
getIgnoreZero(hour, "小时") +
getIgnoreZero(min, "分") +
getIgnoreZero(sec, "秒");
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
/**
* 去掉0
*/
private static String getIgnoreZero(long numer, String unit) {
if(numer == 0) {
return "";
}
return numer + unit;
}
/**
* 比较两个日期时间差 * 比较两个日期时间差
* *
* @param startDate * @param startDate
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!