java闰年的计算方法_Java日期时间API系列18-----Jdk8API类,java日期计算5,星期计算,闰年计算等...

/*** 获取星期值 1-7,星期一到星期日* @param date* @return*/

public static int getDayOfWeek(Date date){

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

}

/*** 获取星期值 1-7,星期一到星期日* @param localDateTime* @return*/

public static int getDayOfWeek(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.getDayOfWeek().getValue();

}

/*** 获取星期值 1-7,星期一到星期日* @param instant* @return*/

public static int getDayOfWeek(Instant instant){

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

}

/*** 获取星期值当前月的最后一天* @param localDate* @return*/

public static LocalDate lastDayOfMonth(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

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

}

/*** 获取星期值当前月的最后一天* @param localDateTime* @return*/

public static LocalDateTime lastDayOfMonth(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

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

}

/*** 获取星期值当前月的最后一天* @param date* @return*/

public static Date lastDayOfMonth(Date date){

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

}

/*** 判断是否闰年* @param localDate* @return*/

public static boolean isLeapYear(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

return localDate.isLeapYear();

}

/*** 判断是否闰年* @param localDateTime* @return*/

public static boolean isLeapYear(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.toLocalDate().isLeapYear();

}

/*** 判断是否闰年* @param date* @return*/

public static boolean isLeapYear(Date date){

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

}

/*** 获取月的天数* @param localDate* @return*/

public static int lengthOfMonth(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

return localDate.lengthOfMonth();

}

/*** 获取月的天数* @param localDateTime* @return*/

public static int lengthOfMonth(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.toLocalDate().lengthOfMonth();

}

/*** 获取月的天数* @param date* @return*/

public static int lengthOfMonth(Date date){

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

}

/*** 获取年的天数* @param localDate* @return*/

public static int lengthOfYear(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

return localDate.lengthOfYear();

}

/*** 获取年的天数* @param localDateTime* @return*/

public static int lengthOfYear(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

return localDateTime.toLocalDate().lengthOfYear();

}

/*** 获取年的天数* @param date* @return*/

public static int lengthOfYear(Date date){

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

}

/*** 下一个星期几* @param localDate* @param dayOfWeek* @return*/

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

Objects.requireNonNull(localDate, "localDate");

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

}

/*** 下一个星期几* @param localDateTime* @param dayOfWeek* @return*/

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

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

}

/*** 下一个星期几* @param date* @param dayOfWeek* @return*/

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

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

}

/*** 上一个星期几* @param localDate* @param dayOfWeek* @return*/

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

Objects.requireNonNull(localDate, "localDate");

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

}

/*** 上一个星期几* @param localDateTime* @param dayOfWeek* @return*/

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

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

}

/*** 上一个星期几* @param date* @param dayOfWeek* @return*/

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

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

}

/*** 获下一个工作日* @param localDate* @return*/

public static LocalDate nextWorkDay(LocalDate localDate){

Objects.requireNonNull(localDate, "localDate");

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

}

/*** 获下一个工作日* @param localDateTime* @return*/

public static LocalDateTime nextWorkDay(LocalDateTime localDateTime){

Objects.requireNonNull(localDateTime, "localDateTime");

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

}

/*** 获下一个工作日* @param date* @return*/

public static Date nextWorkDay(Date date){

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

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值