Commit 80e2f3f3 by 张晋雄

优化时间工具

parent ba280389
......@@ -26,7 +26,7 @@ public class TimeUtils {
int yearDiff = now.get(Calendar.MONTH) - input.get(Calendar.MONTH);;
int yearDiff = now.get(Calendar.YEAR) - input.get(Calendar.YEAR);;
int monthDiff = now.get(Calendar.MONTH) - input.get(Calendar.MONTH);;
int dayDiff = now.get(Calendar.DAY_OF_MONTH) -input.get(Calendar.DAY_OF_MONTH);
int hourDiff = now.get(Calendar.HOUR) - input.get(Calendar.HOUR);
......@@ -40,16 +40,16 @@ public class TimeUtils {
if (yearDiff != 0) {
number = Math.abs(yearDiff);
prefix = PREFIX_YEAR;
suffix = yearDiff > 0 ? SUFFIX_AFTER : SUFFIX_BEFORE;
suffix = yearDiff > 0 ? SUFFIX_BEFORE : SUFFIX_AFTER;
} else if (monthDiff != 0) {
number = Math.abs(monthDiff);
prefix = PREFIX_MONTH;
suffix = monthDiff > 0 ? SUFFIX_AFTER : SUFFIX_BEFORE;
suffix = monthDiff > 0 ? SUFFIX_BEFORE : SUFFIX_AFTER;
} else if (dayDiff != 0) {
number = Math.abs(dayDiff);
prefix = PREFIX_DAY;
suffix = dayDiff > 0 ? SUFFIX_AFTER : SUFFIX_BEFORE;
suffix = dayDiff > 0 ? SUFFIX_BEFORE : SUFFIX_AFTER;
} else if (hourDiff != 0) {
number = Math.abs(hourDiff);
......@@ -59,12 +59,12 @@ public class TimeUtils {
} else if (minuteDiff != 0) {
number = Math.abs(minuteDiff);
prefix = PREFIX_MINUTE;
suffix = monthDiff > 0 ? SUFFIX_AFTER : SUFFIX_BEFORE;
suffix = monthDiff > 0 ? SUFFIX_BEFORE : SUFFIX_AFTER;
} else if (secondDiff != 0) {
number = Math.abs(secondDiff);
prefix = PREFIX_SECOND;
suffix = secondDiff > 0 ? SUFFIX_AFTER : SUFFIX_BEFORE;
suffix = secondDiff > 0 ? SUFFIX_BEFORE : SUFFIX_AFTER;
} else {
number = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment