Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #95

Merged
merged 6 commits into from
Sep 11, 2021
Merged

Dev #95

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ parseToDate(String text, DateTimeFormatter formatter) 根据 formatter解析为
(12)验证日期格式是否正确方法,isValidDate*, 比如isValidDate(String text),验证yyyy-MM-dd 格式字符串是否正确。

(13)根据自定义模板数组解析方法, 比如parseToDate(String text, String[] dateFormatPatterns),dateFormatPatterns 支持多种模板,只要其中一个解析成功就返回对应Date。

(14)解析自然语言时间,今天,明天,下周,下月,明年,昨天,上周,上月,去年等, 比如parseNaturalLanguageToDate(String text),
parseNaturalLanguageToDate(String text, Map<String, String> naturalLanguageMap) 支持自定义解析自然语言时间map
parseNaturalLanguageToDate(String text, Map<String, String> naturalLanguageMap) 支持自定义解析自然语言时间map。

(15)中文日期格式化方法,比如formatToChineseDateStr(Date date, boolean isUpperCase),isUpperCase false:2021年09月11日 true: 二〇二一年九月十一日。

(16)中文日期解析方法,比如parseChineseDateStrToDate(String text),支持:2021年09月11日 和 二〇二一年九月十一日格式日期解析。

注意:格式化和解析与系统时区不同的时间时,使用自定义时区格式化方法,或可以使用withZone方法重新设置时区,比如:
YYYY_MM_DD_HH_MM_SS_SSS_FMT.withZone(ZoneId.of("Europe/Paris") 。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* 2.获取时间加操作方法,plus* 比如plusYears(Date date, long amountToAdd) 当前时间年增加amountToAdd值<br>
* 3.获取时间减操作方法,minus* 比如minusYears(Date date, long amountToSubtract) 当前时间年减少amountToSubtract值<br>
* 4.获取时间修改属性方法,with* 比如withYear(Date date, long newValue) 修改当前时间年值为newValue<br>
* 5.获取比较2个时间方法,between* 比如betweenYears(Date startInclusive, Date endExclusive) 比较2个时间,获取年部分<br>
* 5.获取比较2个时间方法,between* 比如betweenTotalDays(Date startInclusive, Date endExclusive) 比较2个时间,获取相差总天数<br>
* 6.其他常用方法,比如isLeapYear(Date date) 判断是否闰年,isWeekend(Date date) 判断是否周末,isExpiry(String yearMonthStr) 是否过期等<br>
* 7.时区转换计算方法,transform*,比如transform(ZonedDateTime zonedDateTime, String zoneId)<br>
* 8.比较2个时间大小和相等方法,compare*,比如compare(Date date1, Date date2)<br>
Expand Down Expand Up @@ -1628,6 +1628,7 @@ public static LocalDate withDayOfWeek(LocalDate localDate, long newValue){
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenYears(LocalDateTime startInclusive, LocalDateTime endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
Expand All @@ -1642,6 +1643,7 @@ public static long betweenYears(LocalDateTime startInclusive, LocalDateTime endE
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenYears(Date startInclusive, Date endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
Expand All @@ -1656,17 +1658,58 @@ public static long betweenYears(Date startInclusive, Date endExclusive){
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenYears(LocalDate startInclusive, LocalDate endExclusive){
return Period.between(startInclusive, endExclusive).getYears();
}

/**
* 获取2个日期的相差年月天的年数部分,不是相差总年数,
* 比如2020-02-29 2021-03-07,返回1
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodYears(LocalDateTime startInclusive, LocalDateTime endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
return Period.between(DateTimeConverterUtil.toLocalDate(startInclusive),
DateTimeConverterUtil.toLocalDate(endExclusive)).getYears();
}

/**
* 获取2个日期的相差年月天的年数部分,不是相差总年数,
* 比如2020-02-29 2021-03-07,返回1
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodYears(Date startInclusive, Date endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
return Period.between(DateTimeConverterUtil.toLocalDate(startInclusive),
DateTimeConverterUtil.toLocalDate(endExclusive)).getYears();
}

/**
* 获取2个日期的相差年月天的年数部分,不是相差总年数,
* 比如2020-02-29 2021-03-07,返回1
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodYears(LocalDate startInclusive, LocalDate endExclusive){
return Period.between(startInclusive, endExclusive).getYears();
}

/**
* 获取2个日期的相差年月天的月数部分,不是相差总月数,
* 比如2020-02-29 2021-03-07,返回0
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenMonths(LocalDateTime startInclusive, LocalDateTime endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
Expand All @@ -1681,6 +1724,7 @@ public static long betweenMonths(LocalDateTime startInclusive, LocalDateTime end
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenMonths(Date startInclusive, Date endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
Expand All @@ -1695,17 +1739,58 @@ public static long betweenMonths(Date startInclusive, Date endExclusive){
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenMonths(LocalDate startInclusive, LocalDate endExclusive){
return Period.between(startInclusive, endExclusive).getMonths();
}

/**
* 获取2个日期的相差年月天的月数部分,不是相差总月数,
* 比如2020-02-29 2021-03-07,返回0
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodMonths(LocalDateTime startInclusive, LocalDateTime endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
return Period.between(DateTimeConverterUtil.toLocalDate(startInclusive),
DateTimeConverterUtil.toLocalDate(endExclusive)).getMonths();
}

/**
* 获取2个日期的相差年月天的月数部分,不是相差总月数,
* 比如2020-02-29 2021-03-07,返回0
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodMonths(Date startInclusive, Date endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
return Period.between(DateTimeConverterUtil.toLocalDate(startInclusive),
DateTimeConverterUtil.toLocalDate(endExclusive)).getMonths();
}

/**
* 获取2个日期的相差年月天的月数部分,不是相差总月数,
* 比如2020-02-29 2021-03-07,返回0
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodMonths(LocalDate startInclusive, LocalDate endExclusive){
return Period.between(startInclusive, endExclusive).getMonths();
}

/**
* 获取2个日期的相差年月天的天数部分,不是相差总天数,
* 比如2020-02-29 2021-03-07,返回7
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenDays(LocalDateTime startInclusive, LocalDateTime endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
Expand All @@ -1720,6 +1805,7 @@ public static long betweenDays(LocalDateTime startInclusive, LocalDateTime endEx
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenDays(Date startInclusive, Date endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
Expand All @@ -1734,10 +1820,50 @@ public static long betweenDays(Date startInclusive, Date endExclusive){
* @param endExclusive 结束时间
* @return long
*/
@Deprecated
public static long betweenDays(LocalDate startInclusive, LocalDate endExclusive){
return Period.between(startInclusive, endExclusive).getDays();
}

/**
* 获取2个日期的相差年月天的天数部分,不是相差总天数,
* 比如2020-02-29 2021-03-07,返回7
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodDays(LocalDateTime startInclusive, LocalDateTime endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
return Period.between(DateTimeConverterUtil.toLocalDate(startInclusive),
DateTimeConverterUtil.toLocalDate(endExclusive)).getDays();
}

/**
* 获取2个日期的相差年月天的天数部分,不是相差总天数,
* 比如2020-02-29 2021-03-07,返回7
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodDays(Date startInclusive, Date endExclusive){
Objects.requireNonNull(startInclusive, "startInclusive");
Objects.requireNonNull(endExclusive, "endExclusive");
return Period.between(DateTimeConverterUtil.toLocalDate(startInclusive),
DateTimeConverterUtil.toLocalDate(endExclusive)).getDays();
}

/**
* 获取2个日期的相差年月天的天数部分,不是相差总天数,
* 比如2020-02-29 2021-03-07,返回7
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenPeriodDays(LocalDate startInclusive, LocalDate endExclusive){
return Period.between(startInclusive, endExclusive).getDays();
}

/**
* 获取2个日期的相差总天数
* @param startInclusive 开始时间
Expand All @@ -1748,6 +1874,16 @@ public static long betweenTotalDays(LocalDateTime startInclusive, LocalDateTime
return Duration.between(startInclusive, endExclusive).toDays();
}

/**
* 获取2个日期的相差总天数
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenTotalDays(LocalDate startInclusive, LocalDate endExclusive){
return Duration.between(DateTimeConverterUtil.toLocalDateTime(startInclusive), DateTimeConverterUtil.toLocalDateTime(endExclusive)).toDays();
}

/**
* 获取2个日期的相差总天数
* @param startInclusive 开始时间
Expand All @@ -1770,6 +1906,16 @@ public static long betweenTotalHours(LocalDateTime startInclusive, LocalDateTime
return Duration.between(startInclusive, endExclusive).toHours();
}

/**
* 获取2个日期的相差总小时数
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenTotalHours(LocalDate startInclusive, LocalDate endExclusive){
return Duration.between(DateTimeConverterUtil.toLocalDateTime(startInclusive), DateTimeConverterUtil.toLocalDateTime(endExclusive)).toHours();
}

/**
* 获取2个日期的相差总小时数
* @param startInclusive 开始时间
Expand Down Expand Up @@ -1802,6 +1948,16 @@ public static long betweenTotalMinutes(LocalDateTime startInclusive, LocalDateTi
return Duration.between(startInclusive, endExclusive).toMinutes();
}

/**
* 获取2个日期的相差总分钟数
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenTotalMinutes(LocalDate startInclusive, LocalDate endExclusive){
return Duration.between(DateTimeConverterUtil.toLocalDateTime(startInclusive), DateTimeConverterUtil.toLocalDateTime(endExclusive)).toMinutes();
}

/**
* 获取2个日期的相差总分钟数
* @param startInclusive 开始时间
Expand Down Expand Up @@ -1834,6 +1990,16 @@ public static long betweenTotalSeconds(LocalDateTime startInclusive, LocalDateTi
return Duration.between(startInclusive, endExclusive).getSeconds();
}

/**
* 获取2个日期的相差总秒数
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenTotalSeconds(LocalDate startInclusive, LocalDate endExclusive){
return Duration.between(DateTimeConverterUtil.toLocalDateTime(startInclusive), DateTimeConverterUtil.toLocalDateTime(endExclusive)).getSeconds();
}

/**
* 获取2个日期的相差总秒数
* @param startInclusive 开始时间
Expand Down Expand Up @@ -1866,6 +2032,16 @@ public static long betweenTotalMillis(LocalDateTime startInclusive, LocalDateTim
return Duration.between(startInclusive, endExclusive).toMillis();
}

/**
* 获取2个日期的相差总毫秒数
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenTotalMillis(LocalDate startInclusive, LocalDate endExclusive){
return Duration.between(DateTimeConverterUtil.toLocalDateTime(startInclusive), DateTimeConverterUtil.toLocalDateTime(endExclusive)).toMillis();
}

/**
* 获取2个日期的相差总毫秒数
* @param startInclusive 开始时间
Expand Down Expand Up @@ -1898,6 +2074,16 @@ public static long betweenTotalNanos(LocalDateTime startInclusive, LocalDateTime
return Duration.between(startInclusive, endExclusive).toNanos();
}

/**
* 获取2个日期的相差总纳秒数
* @param startInclusive 开始时间
* @param endExclusive 结束时间
* @return long
*/
public static long betweenTotalNanos(LocalDate startInclusive, LocalDate endExclusive){
return Duration.between(DateTimeConverterUtil.toLocalDateTime(startInclusive), DateTimeConverterUtil.toLocalDateTime(endExclusive)).toNanos();
}

/**
* 获取2个日期的相差总纳秒数
* @param startInclusive 开始时间
Expand Down
Loading