|
@@ -1209,4 +1209,27 @@ public final class DateUtils {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
return calendar.get(field);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 叠加日期
|
|
|
+ *
|
|
|
+ * @param date 日期对象
|
|
|
+ * @param other 日期对象
|
|
|
+ * @return 日期对象
|
|
|
+ */
|
|
|
+ public static Date superpose(Date date, Date other) {
|
|
|
+ if (date == null) {
|
|
|
+ return other;
|
|
|
+ } else if (other == null) {
|
|
|
+ return date;
|
|
|
+ }
|
|
|
+
|
|
|
+ long t1 = date.getTime(), t2 = other.getTime(), now = System.currentTimeMillis();
|
|
|
+ if (t1 <= now && t2 <= now) {
|
|
|
+ return t1 < t2 ? other : date;
|
|
|
+ } else if (t1 > now && t2 > now) {
|
|
|
+ return new Date(t1 + t2 - now);
|
|
|
+ }
|
|
|
+ return t1 > now ? date : other;
|
|
|
+ }
|
|
|
}
|