/*** 相同月日比较判断,用于生日,节日等周期性的日期比较判断。
*@paramlocalDate1
*@parammonthDay
*@return
*/
public static booleanisSameMonthDay(LocalDate localDate1, MonthDay monthDay){
Objects.requireNonNull(localDate1,"localDate1");
Objects.requireNonNull(monthDay,"monthDay");returnMonthDay.of(localDate1.getMonthValue(), localDate1.getDayOfMonth()).equals(monthDay);
}/*** 相同月日比较判断,用于生日,节日等周期性的日期比较判断。
*@paramlocalDate1
*@parammonthDayStr MM-dd格式
*@return
*/
public static booleanisSameMonthDay(LocalDate localDate1, String monthDayStr){
Objects.requireNonNull(monthDayStr,"monthDayStr");return isSameMonthDay(localDate1, MonthDay.parse(MONTHDAY_FORMAT_PRE +monthDayStr));
}/*** 相同月日比较判断,用于生日,节日等周期性的日期比较判断。
*@paramlocalDate1
*@paramlocalDate2
*@return
*/
public static booleanisSameMonthDay(LocalDate localDate1, LocalDate localDate2){
Objects.requireNonNull(localDate2,"localDate2");returnisSameMonthDay(localDate1, MonthDay.of(localDate2.getMonthValue(), localDate2.getDayOfMonth()));
}/*** 相同月日比较判断,用于生日,节日等周期性的日期比较判断。
*@paramdate
*@parammonthDayStr MM-dd格式
*@return
*/
public static booleanisSameMonthDay(Date date, String monthDayStr){returnisSameMonthDay(DateTimeConverterUtil.toLocalDate(date), monthDayStr);
}/*** 相同月日比较判断,用于生日,节日等周期性的日期比较判断。
*@paramdate1
*@paramdate2
*@return
*/
public static booleanisSameMonthDay(Date date1, Date date2){
Objects.requireNonNull(date1,"date1");
Objects.requireNonNull(date2,"date2");returnisSameMonthDay(DateTimeConverterUtil.toLocalDate(date1), DateTimeConverterUtil.toLocalDate(date2));
}/*** 相同月日比较判断,与当前日期对比,用于生日,节日等周期性的日期比较判断
*@parammonthDayStr MM-dd格式
*@return
*/
public static booleanisSameMonthDayOfNow(String monthDayStr){returnisSameMonthDay(LocalDate.now(), monthDayStr);
}/*** 下个固定月日相差天数,用于生日,节日等周期性的日期推算
*@paramlocalDate1
*@parammonth
*@paramdayOfMonth
*@return
*/
public static long betweenNextSameMonthDay(LocalDate localDate1, int month, intdayOfMonth) {
Objects.requireNonNull(localDate1,"localDate1");
MonthDay monthDay1=MonthDay.of(localDate1.getMonthValue(), localDate1.getDayOfMonth());
MonthDay monthDay2=MonthDay.of(month, dayOfMonth);//localDate1 月日 小于 month dayOfMonth
if (monthDay1.compareTo(monthDay2) == -1) {returnbetweenTotalDays(localDate1.atStartOfDay(),
localDate1.withMonth(month).withDayOfMonth(dayOfMonth).atStartOfDay());
}else{//闰年2月29
MonthDay leapMonthDay = MonthDay.of(2, 29);if(leapMonthDay.equals(monthDay2)) {
LocalDate nextLeapYear=nextLeapYear(localDate1);returnbetweenTotalDays(localDate1.atStartOfDay(),
nextLeapYear.withMonth(month).withDayOfMonth(dayOfMonth).atStartOfDay());
}else{
LocalDate next= localDate1.plusYears(1);returnbetweenTotalDays(localDate1.atStartOfDay(),
next.withMonth(month).withDayOfMonth(dayOfMonth).atStartOfDay());
}
}
}/*** 下个固定月日相差天数,用于生日,节日等周期性的日期推算
*@paramlocalDate
*@parammonthDayStr MM-dd格式
*@return
*/
public static longbetweenNextSameMonthDay(LocalDate localDate, String monthDayStr) {
Objects.requireNonNull(monthDayStr,"monthDayStr");
MonthDay monthDay2= MonthDay.parse(MONTHDAY_FORMAT_PRE +monthDayStr);returnbetweenNextSameMonthDay(localDate, monthDay2.getMonthValue(), monthDay2.getDayOfMonth());
}/*** 下个固定月日相差天数,用于生日,节日等周期性的日期推算
*@paramdate
*@parammonthDayStr MM-dd格式
*@return
*/
public static longbetweenNextSameMonthDay(Date date, String monthDayStr) {
Objects.requireNonNull(monthDayStr,"monthDayStr");
MonthDay monthDay2= MonthDay.parse(MONTHDAY_FORMAT_PRE +monthDayStr);returnbetweenNextSameMonthDay(DateTimeConverterUtil.toLocalDate(date), monthDay2.getMonthValue(),
monthDay2.getDayOfMonth());
}/*** 下个固定月日相差天数,与当前日期对比,用于生日,节日等周期性的日期推算
*@parammonthDayStr MM-dd格式
*@return
*/
public static longbetweenNextSameMonthDayOfNow(String monthDayStr) {
Objects.requireNonNull(monthDayStr,"monthDayStr");
MonthDay monthDay2= MonthDay.parse(MONTHDAY_FORMAT_PRE +monthDayStr);returnbetweenNextSameMonthDay(LocalDate.now(), monthDay2.getMonthValue(),
monthDay2.getDayOfMonth());
}/*** 下个固定月日相差日期,用于生日,节日等周期性的日期推算
*@paramlocalDate
*@parammonthDayStr MM-dd格式
*@return
*/
public staticLocalDate nextSameMonthDay(LocalDate localDate, String monthDayStr){returnlocalDate.plusDays(betweenNextSameMonthDay(localDate, monthDayStr));
}/*** 下个固定月日相差日期,用于生日,节日等周期性的日期推算
*@paramdate
*@parammonthDayStr MM-dd格式
*@return
*/
public staticDate nextSameMonthDay(Date date, String monthDayStr){returnDateTimeConverterUtil.toDate(nextSameMonthDay(DateTimeConverterUtil.toLocalDate(date), monthDayStr));
}/*** 下个固定月日相差日期,与当前日期对比,用于生日,节日等周期性的日期推算
*@parammonthDayStr MM-dd格式
*@return
*/
public staticDate nextSameMonthDayOfNow(String monthDayStr){return nextSameMonthDay(newDate(), monthDayStr);
}