天天看點

java閏年的計算方法_Java日期時間API系列18-----Jdk8API類,java日期計算5,星期計算,閏年計算等...

public static int getDayOfWeek(Date date){

return DateTimeConverterUtil.toLocalDateTime(date).getDayOfWeek().getValue();

}

public static int getDayOfWeek(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.getDayOfWeek().getValue();

}

public static int getDayOfWeek(Instant instant){

return DateTimeConverterUtil.toLocalDateTime(instant).getDayOfWeek().getValue();

}

public static LocalDate lastDayOfMonth(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

return localDate.with(TemporalAdjusters.lastDayOfMonth());

}

public static LocalDateTime lastDayOfMonth(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.with(TemporalAdjusters.lastDayOfMonth());

}

public static Date lastDayOfMonth(Date date){

return DateTimeConverterUtil.toDate(DateTimeConverterUtil.toLocalDate(date).with(TemporalAdjusters.lastDayOfMonth()));

}

public static boolean isLeapYear(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

return localDate.isLeapYear();

}

public static boolean isLeapYear(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.toLocalDate().isLeapYear();

}

public static boolean isLeapYear(Date date){

return DateTimeConverterUtil.toLocalDateTime(date).toLocalDate().isLeapYear();

}

public static int lengthOfMonth(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

return localDate.lengthOfMonth();

}

public static int lengthOfMonth(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.toLocalDate().lengthOfMonth();

}

public static int lengthOfMonth(Date date){

return DateTimeConverterUtil.toLocalDateTime(date).toLocalDate().lengthOfMonth();

}

public static int lengthOfYear(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

return localDate.lengthOfYear();

}

public static int lengthOfYear(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.toLocalDate().lengthOfYear();

}

public static int lengthOfYear(Date date){

return DateTimeConverterUtil.toLocalDateTime(date).toLocalDate().lengthOfYear();

}

public static LocalDate next(LocalDate localDate, DayOfWeek dayOfWeek){

Objects.requireNonNull(localDate, "localDate");

return localDate.with(TemporalAdjusters.next(dayOfWeek));

}

public static LocalDateTime next(LocalDateTime localDateTime, DayOfWeek dayOfWeek){

return localDateTime.with(TemporalAdjusters.next(dayOfWeek));

}

public static Date next(Date date, DayOfWeek dayOfWeek){

return DateTimeConverterUtil.toDate(DateTimeConverterUtil.toLocalDate(date).with(TemporalAdjusters.next(dayOfWeek)));

}

public static LocalDate previous(LocalDate localDate, DayOfWeek dayOfWeek){

Objects.requireNonNull(localDate, "localDate");

return localDate.with(TemporalAdjusters.previous(dayOfWeek));

}

public static LocalDateTime previous(LocalDateTime localDateTime, DayOfWeek dayOfWeek){

return localDateTime.with(TemporalAdjusters.previous(dayOfWeek));

}

public static Date previous(Date date, DayOfWeek dayOfWeek){

return DateTimeConverterUtil.toDate(DateTimeConverterUtil.toLocalDate(date).with(TemporalAdjusters.previous(dayOfWeek)));

}

public static LocalDate nextWorkDay(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

return localDate.with(TemporalAdjusterExtension.nextWorkDay());

}

public static LocalDateTime nextWorkDay(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.with(TemporalAdjusterExtension.nextWorkDay());

}

public static Date nextWorkDay(Date date){

return DateTimeConverterUtil.toDate(DateTimeConverterUtil.toLocalDate(date).with(TemporalAdjusterExtension.nextWorkDay()));

}