时间处理工具类

young 509 2021-10-18

Date处理采用joda-time工具类

public class DateUtils {

	public final static String SIMPLE_FORMAT = "yyyy-MM-dd";
	public static final String DETAIL_FORMAT = "yyyy-MM-dd HH:mm:ss";
	public static final String NORMAL_FORMAT = "yyyyMMdd";
	public static final String SIMPLE_TIME = "HHmmss";
	public static final String NORMAL_TIME = "HH:mm:ss";
	public static final String TEXT_HOUR_UNIT = "小时";
	public static final String TEXT_MINUTE_UNIT = "分钟";
	public static final String TEXT_SECOND_UNIT = "秒";
	public static final List<String> WEEK_DAYS_CN = Arrays.asList("星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日");
	public static final List<String> MONTH_CN =
			Arrays.asList("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月");
	public static final int QUANTUM_DAY_HOUR = 24;
	public static final int QUANTUM_SECOND_MILLIS = 1000;
	private static final String CHINA_TIME_ZONE = "+8";
	public static final ZoneOffset CHINA_ZONE = ZoneOffset.of(CHINA_TIME_ZONE);
	private static final int ONE = 1;
	private static final int ZERO = 0;

	public static Date getDate() {
		return new Date();
	}

	public static long getMilliSecond(LocalDateTime localDateTime, ZoneOffset zoneOffset) {
		return localDateTime.toInstant(zoneOffset).toEpochMilli();
	}

	public static long getMilliSecond(LocalDateTime localDateTime) {
		return localDateTime.toInstant(ZoneOffset.of(CHINA_TIME_ZONE)).toEpochMilli();
	}

	public static Date getDate(int year, int month) {
		return new DateTime(year, month, ONE, ZERO, ZERO).toDate();
	}

	public static Date getDate(int year, int month, int dayOfMonth) {
		return new DateTime(year, month, dayOfMonth, ZERO, ZERO).toDate();
	}

	public static Date getDate(int year, int month, int dayOfMonth, int hour) {
		return new DateTime(year, month, dayOfMonth, hour, ZERO).toDate();
	}

	public static Date getDate(int year, int month, int dayOfMonth, int hour, int minute) {
		return new DateTime(year, month, dayOfMonth, hour, minute).toDate();
	}

	public static Date getDate(int year, int month, int dayOfMonth, int hour, int minute, int second) {
		return new DateTime(year, month, dayOfMonth, hour, minute, second).toDate();
	}

	public static Date getDate(long time) {
		return new Date(time);
	}

	public static Date getDate(LocalDate localDate) {
		if (localDate != null) {
			ZoneId zone = ZoneId.systemDefault();
			Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
			return Date.from(instant);
		}
		return null;
	}

	public static Date getDate(LocalDateTime localDateTime) {
		if (localDateTime != null) {
			ZoneId zone = ZoneId.systemDefault();
			Instant instant = localDateTime.atZone(zone).toInstant();
			return Date.from(instant);
		}
		return null;
	}

	public static LocalDate getLocalDate() {
		return LocalDate.now();
	}

	public static LocalDate getLocalDate(Date date) {
		return getLocalDate(getLocalDateTime(date));
	}

	public static LocalDate getLocalDate(LocalDateTime localDateTime) {
		return localDateTime.toLocalDate();
	}

	public static LocalDate getLocalDate(int year, int month, int dayOfMonth) {
		return LocalDate.of(year, month, dayOfMonth);
	}

	public static LocalDate getLocalDate(int year, Month month, int dayOfMonth) {
		return LocalDate.of(year, month, dayOfMonth);
	}

	public static LocalDate getLocalDate(int year, int dayOfYear) {
		return LocalDate.ofYearDay(year, dayOfYear);
	}

	public static LocalDateTime getLocalDateTime() {
		return LocalDateTime.now();
	}

	public static LocalDateTime getLocalDateTime(Date date) {
		Instant instant = date.toInstant();
		return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
	}

	public static LocalDateTime getLocalDateTime(int year, Month month, int dayOfMonth, int hour, int minute) {
		return LocalDateTime.of(year, month, dayOfMonth, hour, minute);
	}

	public static LocalDateTime getLocalDateTime(int year, Month month, int dayOfMonth, int hour, int minute,
			int second) {
		return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second);
	}

	public static LocalDateTime getLocalDateTime(int year, Month month, int dayOfMonth, int hour, int minute,
			int second, int nanoOfSecond) {
		return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond);
	}

	public static LocalDateTime getLocalDateTime(int year, int month, int dayOfMonth, int hour, int minute) {
		return LocalDateTime.of(year, month, dayOfMonth, hour, minute);
	}

	public static LocalDateTime getLocalDateTime(int year, int month, int dayOfMonth, int hour, int minute,
			int second) {
		return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second);
	}

	public static LocalDateTime getLocalDateTime(int year, int month, int dayOfMonth, int hour, int minute, int second,
			int nanoOfSecond) {
		return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond);
	}

	public static LocalDateTime getLocalDateTime(LocalDate localDate, LocalTime localTime) {
		return LocalDateTime.of(localDate, localTime);
	}

	public static LocalTime getLocalTime() {
		return LocalTime.now();
	}

	public static LocalTime getLocalTime(Date date) {
		return getLocalTime(getLocalDateTime(date));
	}

	public static LocalTime getLocalTime(LocalDateTime localDateTime) {
		return localDateTime.toLocalTime();
	}

	public static LocalTime getLocalTime(int hour, int minute) {
		return LocalTime.of(hour, minute);
	}

	public static LocalTime getLocalTime(int hour, int minute, int second) {
		return LocalTime.of(hour, minute, second);
	}

	public static LocalTime getLocalTime(int hour, int minute, int second, int nanoOfSecond) {
		return LocalTime.of(hour, minute, second, nanoOfSecond);
	}

	public static LocalDateTime getLocalDateTime(LocalDate localDate) {
		return localDate.atTime(0, 0);
	}


	public static String format(Date date, String pattern) {
		if (date != null && StringUtils.isNotBlank(pattern)) {
			return new DateTime(date).toString(pattern);
		}
		return null;
	}

	public static String format(long time, String pattern) {
		if (time > ZERO && StringUtils.isNotBlank(pattern)) {
			return new DateTime(time).toString(pattern);
		}
		return null;
	}

	public static String format(LocalDate localDate, String pattern) {
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
		return localDate == null ? null : dateTimeFormatter.format(localDate);
	}

	public static String format(LocalDateTime localDateTime, String pattern) {
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
		return localDateTime == null ? null : dateTimeFormatter.format(localDateTime);
	}

	public static String format(TemporalAccessor temporalAccessor, String pattern) {
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
		return temporalAccessor == null ? null : dateTimeFormatter.format(temporalAccessor);
	}

	public static String defaultFormat(long time) {
		if (time > ZERO) {
			return new DateTime(time).toString(DETAIL_FORMAT);
		}
		return null;
	}

	public static String defaultFormat(Date date) {
		if (date != null) {
			return new DateTime(date).toString(DETAIL_FORMAT);
		}
		return null;
	}

	public static Date parse(String source, String pattern) throws ParseException {
		if (StringUtils.isNotBlank(pattern) && StringUtils.isNotBlank(source)) {
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
			return simpleDateFormat.parse(source);
		}
		return null;
	}

	public static LocalTime parseLocalTime(String timeStr, String pattern) {
		return LocalTime.parse(timeStr, DateTimeFormatter.ofPattern(pattern));
	}

	public static LocalTime parseLocalTime(String timeStr) {
		return LocalTime.parse(timeStr);
	}

	public static LocalDate parseLocalDate(String dateStr, String pattern) {
		return LocalDate.parse(dateStr, DateTimeFormatter.ofPattern(pattern));
	}

	public static LocalDate parseLocalDate(String dateStr) {
		return LocalDate.parse(dateStr);
	}

	public static LocalDateTime parseLocalDateTime(String dateTimeStr, String pattern) {
		return LocalDateTime.parse(dateTimeStr, DateTimeFormatter.ofPattern(pattern));
	}


	public static LocalDateTime parseLocalDateTime(String dateTimeStr) {
		return LocalDateTime.parse(dateTimeStr);
	}

	/************************************************
	 * 比较
	 ***********************************************/

	public static boolean isAfterNow(Date date) {
		return date == null ? false : new DateTime(date).isAfterNow();
	}

	public static boolean isBeforeNow(Date date) {
		return date == null ? false : new DateTime(date).isBeforeNow();
	}

	public static boolean isEqualNow(Date date) {
		return date == null ? false : new DateTime(date).isEqualNow();
	}

	public static boolean isDateEqualNow(Date date) {
		return date == null ? false : getLocalDateTime(date).toLocalDate().isEqual(LocalDate.now());
	}

	public static boolean isDateBefore(Date date1, Date date2) {
		if (date1 != null && date2 != null) {
			return getLocalDateTime(date1).toLocalDate().isBefore(getLocalDateTime(date2).toLocalDate());
		}
		return false;
	}

	public static boolean isDateAfter(Date date1, Date date2) {
		if (date1 != null && date2 != null) {
			return getLocalDateTime(date1).toLocalDate().isAfter(getLocalDateTime(date2).toLocalDate());
		}
		return false;
	}

	public static boolean isDateTimeAfter(Date date1, Date date2) {
		if (date1 != null && date2 != null) {
			return date1.after(date2);
		}
		return false;
	}

	public static boolean isDateTimeBefore(Date date1, Date date2) {
		if (date1 != null && date2 != null) {
			return date1.before(date2);
		}
		return false;
	}

	public static boolean isDateTimeEqual(Date date1, Date date2) {
		if (date1 != null && date2 != null) {
			return date1.equals(date2);
		} else if (date1 == null && date2 == null) {
			return true;
		}
		return false;
	}

	public static boolean isEqual(LocalDate firstDate, LocalDate secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.isEqual(secondDate);
		} else {
			return firstDate == null && secondDate == null;
		}
	}

	public static boolean isEqual(LocalDateTime firstDate, LocalDateTime secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.isEqual(secondDate);
		} else {
			return firstDate == null && secondDate == null;
		}
	}

	public static boolean isEqual(LocalTime firstDate, LocalTime secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.equals(secondDate);
		} else {
			return firstDate == null && secondDate == null;
		}
	}

	public static boolean isAfter(LocalDate firstDate, LocalDate secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.isAfter(secondDate);
		}
		return false;
	}

	public static boolean isAfter(Date firstDate, Date secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.after(secondDate);
		}
		return false;
	}

	public static boolean isAfter(LocalDateTime firstDate, LocalDateTime secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.isAfter(secondDate);
		}
		return false;
	}

	public static boolean isBefore(Date firstDate, Date secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.before(secondDate);
		}
		return false;
	}

	public static boolean isBefore(LocalDate firstDate, LocalDate secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.isBefore(secondDate);
		}
		return false;
	}

	public static boolean isBefore(LocalDateTime firstDate, LocalDateTime secondDate) {
		if (firstDate != null && secondDate != null) {
			return firstDate.isBefore(secondDate);
		}
		return false;
	}

	/***************************************************
	 * 获取属性
	 ***************************************************/
	public static int getYear(Date date) {
		return new DateTime(date).getYear();
	}

	/**
	 * @param date
	 * @return 1<= return <= 12
	 */
	public static int getMonth(Date date) {
		return new DateTime(date).getMonthOfYear();
	}

	public static Month getMonthEnum(Date date) {
		return Month.of(new DateTime(date).getMonthOfYear());
	}

	public static String getMonthCn(Date date) {
		return MONTH_CN.get(getMonth(date) - 1);
	}

	public static int getDayOfMonth(Date date) {
		return new DateTime(date).getDayOfMonth();
	}

	/**
	 * @param date
	 * @return 1<= return <= 7
	 */
	public static int getDayOfWeek(Date date) {
		return new DateTime(date).getDayOfWeek();
	}

	public static DayOfWeek getDayOfWeekEnum(Date date) {
		return DayOfWeek.of(new DateTime(date).getDayOfWeek());
	}

	public static String getDayOfWeekCN(Date date) {
		return WEEK_DAYS_CN.get(getDayOfWeek(date) - 1);
	}

	public static int getDayOfYear(Date date) {
		return new DateTime(date).getDayOfYear();
	}

	public static int getHour(Date date) {
		return new DateTime(date).getHourOfDay();
	}

	public static int getMinuteOfDay(Date date) {
		return new DateTime(date).getMinuteOfDay();
	}

	public static int getMinuteOfHour(Date date) {
		return new DateTime(date).getMinuteOfHour();
	}

	public static int getSecondOfDay(Date date) {
		return new DateTime(date).getSecondOfDay();
	}

	public static int getSecondOfMinute(Date date) {
		return new DateTime(date).getSecondOfMinute();
	}

	public static int getMillisOfDay(Date date) {
		return new DateTime(date).getMillisOfDay();
	}

	public static int getMillisOfSecond(Date date) {
		return new DateTime(date).getMillisOfSecond();
	}

	public static int getWeekyear(Date date) {
		return new DateTime(date).getWeekyear();
	}

	public static int getWeekOfWeekyear(Date date) {
		return new DateTime(date).getWeekOfWeekyear();
	}

	public static int getLengthOfMonth(LocalDateTime localDateTime) {
		return localDateTime.toLocalDate().lengthOfMonth();
	}

	public static int getLengthOfMonth(Date date) {
		return getLengthOfMonth(getLocalDateTime(date));
	}

	public static Date getFirstDayOfMonth(Date date) {
		return getDate(getFirstDayOfMonth(getLocalDateTime(date)));
	}

	public static LocalDateTime getFirstDayOfMonth(LocalDateTime localDateTime) {
		return localDateTime.with(TemporalAdjusters.firstDayOfMonth());
	}

	public static Date getLastDayOfMonth(Date date) {
		return getDate(getLastDayOfMonth(getLocalDateTime(date)));
	}

	public static LocalDateTime getLastDayOfMonth(LocalDateTime localDateTime) {
		return localDateTime.with(TemporalAdjusters.lastDayOfMonth());
	}

	public static boolean isLeapYear(Date date) {
		return getLocalDateTime(date).toLocalDate().isLeapYear();
	}

	public static int getLengthOfMonth(LocalDate localDate) {
		return localDate.lengthOfMonth();
	}

	public static LocalDate getFirstDayOfMonth(LocalDate localDate) {
		return localDate.with(TemporalAdjusters.firstDayOfMonth());
	}

	public static LocalDate getLastDayOfMonth(LocalDate localDate) {
		return localDate.with(TemporalAdjusters.lastDayOfMonth());
	}



	/********************************************
	 * 修改属性
	 *******************************************/
	public static Date changeYear(Date date, int year) {
		return new DateTime(date).withYear(year).toDate();
	}

	public static Date changeMonth(Date date, int month) {
		return new DateTime(date).withMonthOfYear(month).toDate();
	}

	public static Date changeDay(Date date, int day) {
		return new DateTime(date).withDayOfMonth(day).toDate();
	}

	public static Date changeHour(Date date, int hour) {
		return new DateTime(date).withHourOfDay(hour).toDate();
	}

	public static Date changeMinute(Date date, int minute) {
		return new DateTime(date).withMinuteOfHour(minute).toDate();
	}

	public static Date changeSecond(Date date, int second) {
		return new DateTime(date).withSecondOfMinute(second).toDate();
	}

    public static LocalDate changeYear(LocalDate date, int year) {
        return date.withYear(year);
    }

    public static LocalDate changeMonth(LocalDate date, int month) {
        return date.withMonth(month);
    }

    public static LocalDate changeDayOfYear(LocalDate date, int dayOfYear) {
        return date.withDayOfMonth(dayOfYear);
    }

    public static LocalDate changeDayOfMonth(LocalDate date, int dayOfMonth) {
        return date.withDayOfMonth(dayOfMonth);
    }

    public static LocalDateTime changeYear(LocalDateTime date, int year) {
        return date.withYear(year);
    }

    public static LocalDateTime changeMonth(LocalDateTime date, int month) {
        return date.withMonth(month);
    }

    public static LocalDateTime changeDayOfYear(LocalDateTime date, int dayOfYear) {
        return date.withDayOfMonth(dayOfYear);
    }

    public static LocalDateTime changeDayOfMonth(LocalDateTime date, int dayOfMonth) {
        return date.withDayOfMonth(dayOfMonth);
    }

    public static LocalDateTime changeHour(LocalDateTime date, int hour) {
        return date.withHour(hour);
    }

    public static LocalDateTime changeMinute(LocalDateTime date, int minute) {
        return date.withMinute(minute);
    }

    public static LocalDateTime changeSecond(LocalDateTime date, int second) {
        return date.withSecond(second);
    }


	/**********************************************
	 * 时间加减
	 **********************************************/
	public static Date plusDays(Date date, int days) {
		return new DateTime(date).plusDays(days).toDate();
	}

	public static Date plusHours(Date date, int hours) {
		return new DateTime(date).plusHours(hours).toDate();
	}

	public static Date plusMillis(Date date, int millis) {
		return new DateTime(date).plusMillis(millis).toDate();
	}

	public static Date plusMinutes(Date date, int minutes) {
		return new DateTime(date).plusMinutes(minutes).toDate();
	}

	public static Date plusMonths(Date date, int months) {
		return new DateTime(date).plusMonths(months).toDate();
	}

	public static Date plusSeconds(Date date, int seconds) {
		return new DateTime(date).plusSeconds(seconds).toDate();
	}

	public static Date plusWeeks(Date date, int weeks) {
		return new DateTime(date).plusWeeks(weeks).toDate();
	}

	public static Date plusYears(Date date, int years) {
		return new DateTime(date).plusYears(years).toDate();
	}

	public static Date minusDays(Date date, int days) {
		return new DateTime(date).minusDays(days).toDate();
	}

	public static Date minusHours(Date date, int hours) {
		return new DateTime(date).minusHours(hours).toDate();
	}

	public static Date minusMillis(Date date, int millis) {
		return new DateTime(date).minusMillis(millis).toDate();
	}

	public static Date minusMinutes(Date date, int minutes) {
		return new DateTime(date).minusMinutes(minutes).toDate();
	}

	public static Date minusMonths(Date date, int months) {
		return new DateTime(date).minusMonths(months).toDate();
	}

	public static Date minusSeconds(Date date, int seconds) {
		return new DateTime(date).minusSeconds(seconds).toDate();
	}

	public static Date minusWeeks(Date date, int weeks) {
		return new DateTime(date).minusWeeks(weeks).toDate();
	}

	public static Date minusYears(Date date, int years) {
		return new DateTime(date).minusYears(years).toDate();
	}

	/********************************************
	 * 时间差转换
	 ********************************************/
	public static Period timeDifferenceTransform(Date date1, Date date2) {
		long time1 = date1.getTime();
		long time2 = date2.getTime();
		return new Interval(Math.min(time1, time2), Math.max(time1, time2)).toPeriod();
	}

	public static Period millisTransform(long millis) {
		return new Interval(ZERO, millis).toPeriod();
	}

	public static Period secondsTransform(int seconds) {
		return new Interval(ZERO, seconds * QUANTUM_SECOND_MILLIS).toPeriod();
	}

	public static String formatDaysDiffUnit(Date date1, Date date2, boolean showZeroUnit) {
		return formatDiffUnit(timeDifferenceTransform(date1, date2), showZeroUnit);
	}

	public static String formatDaysDiffUnit(Date date1, Date date2) {
		return formatDiffUnit(timeDifferenceTransform(date1, date2), false);
	}

	public static String formatMillisUnit(long millis, boolean showZeroUnit) {
		return formatDiffUnit(millisTransform(millis), showZeroUnit);
	}

	public static String formatMillisUnit(long millis) {
		return formatDiffUnit(millisTransform(millis), false);
	}

	public static String formatSecondsUnit(int seconds, boolean showZeroUnit) {
		return formatDiffUnit(secondsTransform(seconds), showZeroUnit);
	}

	public static String formatSecondsUnit(int seconds) {
		return formatDiffUnit(secondsTransform(seconds), false);
	}

	/*******************************************
	 * 时间差计算
	 *******************************************/
	public static long daysDiffAbs(Date beginDate, Date endDate) {
		return getDuration(beginDate, endDate).getStandardDays();
	}

	public static long daysDiff(Date beginDate, Date endDate) {
		return Days.daysBetween(new DateTime(beginDate), new DateTime(endDate)).getDays();
	}

	public static long secondsDiffAbs(Date beginDate, Date endDate) {
		return getDuration(beginDate, endDate).getStandardSeconds();
	}

	public static long secondsDiff(Date beginDate, Date endDate) {
		return Seconds.secondsBetween(new DateTime(beginDate), new DateTime(endDate)).getSeconds();
	}

	public static long hourDiffAbs(Date beginDate, Date endDate) {
		return getDuration(beginDate, endDate).getStandardHours();
	}

	public static long hourDiff(Date beginDate, Date endDate) {
		return Hours.hoursBetween(new DateTime(beginDate), new DateTime(endDate)).getHours();
	}

	public static long minutesDiffAbs(Date beginDate, Date endDate) {
		return getDuration(beginDate, endDate).getStandardMinutes();
	}

	public static long minutesDiff(Date beginDate, Date endDate) {
		return Minutes.minutesBetween(new DateTime(beginDate), new DateTime(endDate)).getMinutes();
	}

	public static long millisDiff(LocalDateTime minTime, LocalDateTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toMillis();
	}

	public static long millisDiffAbs(LocalDateTime minTime, LocalDateTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toMillis());
	}

	public static long secondDiff(LocalDateTime minTime, LocalDateTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toMillis() / 1000;
	}

	public static long secondDiffAbs(LocalDateTime minTime, LocalDateTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toMillis() / 1000);
	}

	public static long minutesDiff(LocalDateTime minTime, LocalDateTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toMinutes();
	}

	public static long minutesDiffAbs(LocalDateTime minTime, LocalDateTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toMinutes());
	}


	public static long hoursDiff(LocalDateTime minTime, LocalDateTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toHours();
	}

	public static long hoursDiffAbs(LocalDateTime minTime, LocalDateTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toHours());
	}

	public static long daysDiff(LocalDateTime minTime, LocalDateTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toDays();
	}

	public static long daysDiffAbs(LocalDateTime minTime, LocalDateTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toDays());
	}

	public static long millisDiff(LocalTime minTime, LocalTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toMillis();
	}

	public static long millisDiffAbs(LocalTime minTime, LocalTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toMillis());
	}

	public static long secondDiff(LocalTime minTime, LocalTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toMillis() / 1000;
	}

	public static long secondDiffAbs(LocalTime minTime, LocalTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toMillis() / 1000);
	}

	public static long minutesDiff(LocalTime minTime, LocalTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toMinutes();
	}

	public static long minutesDiffAbs(LocalTime minTime, LocalTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toMinutes());
	}

	public static long hoursDiff(LocalTime minTime, LocalTime maxTime) {
		return java.time.Duration.between(minTime, maxTime).toHours();
	}

	public static long hoursDiffAbs(LocalTime minTime, LocalTime maxTime) {
		return Math.abs(java.time.Duration.between(minTime, maxTime).toHours());
	}


	public static long daysDiff(LocalDate minTime, LocalDate maxTime) {
		return java.time.Duration.between(getLocalDateTime(minTime), getLocalDateTime(maxTime)).toDays();
	}

	public static long daysDiffAbs(LocalDate minTime, LocalDate maxTime) {
		return Math.abs(java.time.Duration.between(getLocalDateTime(minTime), getLocalDateTime(maxTime)).toDays());
	}



	/******************************** 获取连续时间 *****************************/

	public static List<LocalDateTime> getContinuousLocalDate(LocalDateTime beginDate, long countNumber) {
		return getContinuousLocalDateTime(beginDate, countNumber, false);
	}

	public static List<LocalDateTime> getContinuousLocalDateTime(LocalDateTime beginDate, long countNumber,
			boolean skipBegin) {
		Stream<LocalDateTime> limit = getContinuousLocalDateTimeSteam(beginDate, countNumber, skipBegin);
		return limit.collect(Collectors.toList());
	}

	public static List<LocalDate> getContinuousLocalDate(LocalDate beginDate, long countNumber) {
		return getContinuousLocalDate(beginDate, countNumber, false);
	}

	public static List<LocalDate> getContinuousLocalDate(LocalDate beginDate, long countNumber, boolean skipBegin) {
		Stream<LocalDate> limit = getContinuousLocalDateSteam(beginDate, countNumber, skipBegin);
		return limit.collect(Collectors.toList());
	}

	public static List<Date> getContinuousDate(Date beginDate, long countNumber) {
		return getContinuousDate(beginDate, countNumber, false);
	}

	public static List<Date> getContinuousDate(Date beginDate, long countNumber, boolean skipBegin) {
		Stream<Date> limit = getContinuousDateSteam(beginDate, countNumber, skipBegin);
		return limit.collect(Collectors.toList());
	}

	public static List<String> getContinuousLocalDateFormat(LocalDateTime beginDate, long countNumber, String pattern) {
		return getContinuousLocalDateTimeFormat(beginDate, countNumber, pattern, false);
	}

	public static List<String> getContinuousLocalDateTimeFormat(LocalDateTime beginDate, long countNumber,
			String pattern, boolean skipBegin) {
		Stream<LocalDateTime> iterate = getContinuousLocalDateTimeSteam(beginDate, countNumber, skipBegin);
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
		return iterate.map(dateTimeFormatter::format).collect(Collectors.toList());
	}

	public static List<String> getContinuousLocalDateFormat(LocalDate beginDate, long countNumber, String pattern) {
		return getContinuousLocalDateFormat(beginDate, countNumber, pattern, false);
	}

	public static List<String> getContinuousLocalDateFormat(LocalDate beginDate, long countNumber, String pattern,
			boolean skipBegin) {
		Stream<LocalDate> iterate = getContinuousLocalDateSteam(beginDate, countNumber, skipBegin);
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
		return iterate.map(dateTimeFormatter::format).collect(Collectors.toList());
	}

	public static List<String> getContinuousDateFormat(Date beginDate, long countNumber, String pattern) {
		return getContinuousDateFormat(beginDate, countNumber, pattern, false);
	}

	public static List<String> getContinuousDateFormat(Date beginDate, long countNumber, String pattern,
			boolean skipBegin) {
		Stream<Date> iterate = getContinuousDateSteam(beginDate, countNumber, skipBegin);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
		return iterate.map(simpleDateFormat::format).collect(Collectors.toList());
	}

	public static List<LocalDateTime> getContinuousLocalDateTime(LocalDateTime beginDate, LocalDateTime endDate) {
		return getContinuousLocalDateTime(beginDate, endDate, false, false);
	}

	public static List<LocalDateTime> getContinuousLocalDateTime(LocalDateTime beginDate, LocalDateTime endDate,
			boolean skipBegin, boolean skipEnd) {
		Stream<LocalDateTime> limit = getContinuousLocalDateTimeSteam(beginDate, endDate, skipBegin, skipEnd);
		return limit.collect(Collectors.toList());
	}

	public static List<LocalDate> getContinuousLocalDate(LocalDate beginDate, LocalDate endDate) {
		return getContinuousLocalDate(beginDate, endDate, false, false);
	}

	public static List<LocalDate> getContinuousLocalDate(LocalDate beginDate, LocalDate endDate, boolean skipBegin,
			boolean skipEnd) {
		Stream<LocalDate> limit = getContinuousLocalDateSteam(beginDate, endDate, skipBegin, skipEnd);
		return limit.collect(Collectors.toList());
	}

	public static List<Date> getContinuousDate(Date beginDate, Date endDate) {
		return getContinuousDate(beginDate, endDate, false, false);
	}

	public static List<Date> getContinuousDate(Date beginDate, Date endDate, boolean skipBegin, boolean skipEnd) {
		Stream<Date> limit = getContinuousDateSteam(beginDate, endDate, skipBegin, skipEnd);
		return limit.collect(Collectors.toList());
	}

	public static List<String> getContinuousLocalDateTimeFormat(LocalDateTime beginDate, LocalDateTime endDate,
			String pattern) {
		return getContinuousLocalDateTimeFormat(beginDate, endDate, pattern, false, false);
	}

	public static List<String> getContinuousLocalDateTimeFormat(LocalDateTime beginDate, LocalDateTime endDate,
			String pattern, boolean skipBegin, boolean skipEnd) {
		Stream<LocalDateTime> iterate = getContinuousLocalDateTimeSteam(beginDate, endDate, skipBegin, skipEnd);
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
		return iterate.map(dateTimeFormatter::format).collect(Collectors.toList());
	}

	public static List<String> getContinuousLocalDateFormat(LocalDate beginDate, LocalDate endDate, String pattern) {
		return getContinuousLocalDateFormat(beginDate, endDate, pattern, false, false);
	}

	public static List<String> getContinuousLocalDateFormat(LocalDate beginDate, LocalDate endDate, String pattern,
			boolean skipBegin, boolean skipEnd) {
		Stream<LocalDate> iterate = getContinuousLocalDateSteam(beginDate, endDate, skipBegin, skipEnd);
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
		return iterate.map(dateTimeFormatter::format).collect(Collectors.toList());
	}

	public static List<String> getContinuousDateFormat(Date beginDate, Date endDate, String pattern) {
		return getContinuousDateFormat(beginDate, endDate, pattern, false, false);
	}

	public static List<String> getContinuousDateFormat(Date beginDate, Date endDate, String pattern, boolean skipBegin,
			boolean skipEnd) {
		Stream<Date> iterate = getContinuousDateSteam(beginDate, endDate, skipBegin, skipEnd);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
		return iterate.map(simpleDateFormat::format).collect(Collectors.toList());
	}

	private static String formatDiffUnit(Period period, boolean showZeroUnit) {
		StringBuilder format = new StringBuilder();
		boolean haveHour = period.getHours() + period.getDays() * QUANTUM_DAY_HOUR > ZERO;
		if (haveHour) {
			format.append(period.getHours() + period.getDays() * QUANTUM_DAY_HOUR).append(TEXT_HOUR_UNIT);
		}
		boolean haveMinutes = period.getMinutes() > ZERO;
		if (haveMinutes) {
			format.append(period.getMinutes()).append(TEXT_MINUTE_UNIT);
		} else if (showZeroUnit && haveHour) {
			format.append(ZERO).append(TEXT_MINUTE_UNIT);
		}
		if (period.getSeconds() >= ZERO) {
			format.append(period.getSeconds()).append(TEXT_SECOND_UNIT);
		}
		return format.toString();

	}

	private static Duration getDuration(Date date1, Date date2) {
		long time1 = date1.getTime();
		long time2 = date2.getTime();
		return new Interval(Math.min(time1, time2), Math.max(time1, time2)).toDuration();
	}

	private static Stream<LocalDateTime> getContinuousLocalDateTimeSteam(LocalDateTime beginDate, long countNumber,
			boolean skipBegin) {
		Stream<LocalDateTime> iterate;
		if (countNumber < ZERO) {
			iterate = Stream.iterate(beginDate, date -> date.minusDays(ONE));
			countNumber = Math.abs(countNumber);
		} else {
			iterate = Stream.iterate(beginDate, date -> date.plusDays(ONE));
		}
		if (skipBegin) {
			iterate = iterate.skip(ONE);
		}
		return iterate.limit(countNumber);
	}

	private static Stream<LocalDate> getContinuousLocalDateSteam(LocalDate beginDate, long countNumber,
			boolean skipBegin) {
		Stream<LocalDate> iterate;
		if (countNumber < ZERO) {
			iterate = Stream.iterate(beginDate, date -> date.minusDays(ONE));
			countNumber = Math.abs(countNumber);
		} else {
			iterate = Stream.iterate(beginDate, date -> date.plusDays(ONE));
		}
		if (skipBegin) {
			iterate = iterate.skip(ONE);
		}
		return iterate.limit(countNumber);
	}

	private static Stream<Date> getContinuousDateSteam(Date beginDate, long countNumber, boolean skipBegin) {
		Stream<Date> iterate;
		if (countNumber < ZERO) {
			iterate = Stream.iterate(beginDate, date -> minusDays(date, ONE));
			countNumber = Math.abs(countNumber);
		} else {
			iterate = Stream.iterate(beginDate, date -> plusDays(date, ONE));
		}
		if (skipBegin) {
			iterate = iterate.skip(ONE);
		}
		return iterate.limit(countNumber);
	}

	private static Stream<LocalDateTime> getContinuousLocalDateTimeSteam(LocalDateTime beginDate, LocalDateTime endDate,
			boolean skipBegin, boolean skipEnd) {
		long countNumber = daysDiff(beginDate, endDate) + ONE;
		Stream<LocalDateTime> iterate;
		if (isBefore(beginDate, endDate)) {
			iterate = Stream.iterate(beginDate, date -> date.plusDays(ONE));
		} else {
			iterate = Stream.iterate(beginDate, date -> date.minusDays(ONE));
		}
		if (skipBegin) {
			iterate = iterate.skip(ONE);
			countNumber -= ONE;
		}
		if (skipEnd) {
			countNumber -= ONE;
		}
		return iterate.limit(countNumber);
	}

	private static Stream<LocalDate> getContinuousLocalDateSteam(LocalDate beginDate, LocalDate endDate,
			boolean skipBegin, boolean skipEnd) {
		long countNumber = daysDiff(beginDate, endDate) + ONE;
		Stream<LocalDate> iterate;
		if (isBefore(beginDate, endDate)) {
			iterate = Stream.iterate(beginDate, date -> date.plusDays(ONE));
		} else {
			iterate = Stream.iterate(beginDate, date -> date.minusDays(ONE));
		}
		if (skipBegin) {
			iterate = iterate.skip(ONE);
			countNumber -= ONE;
		}
		if (skipEnd) {
			countNumber -= ONE;
		}
		return iterate.limit(countNumber);
	}

	private static Stream<Date> getContinuousDateSteam(Date beginDate, Date endDate, boolean skipBegin,
			boolean skipEnd) {
		long countNumber = daysDiffAbs(beginDate, endDate) + ONE;
		Stream<Date> iterate;
		if (isDateBefore(beginDate, endDate)) {
			iterate = Stream.iterate(beginDate, date -> plusDays(date, ONE));
		} else {
			iterate = Stream.iterate(beginDate, date -> minusDays(date, ONE));
		}
		if (skipBegin) {
			iterate = iterate.skip(ONE);
			countNumber -= ONE;
		}
		if (skipEnd) {
			countNumber -= ONE;
		}
		return iterate.limit(countNumber);
	}
}