/**
* 自定义年月日
* @param year 年
* @param month 月
* @param day 日
* @return LocalDate
*/
public static LocalDate getLocalDateByYearAndMonthAndDay(int year , int month , int day){
LocalDate nowDate = LocalDate.now();
//获取相差年份
int differYear = year - nowDate.getYear();
int differMonth = differYear * 12 + month - nowDate.getMonthValue();
//设置成当前月的第一天
LocalDate tempDate = nowDate.plusMonths(differMonth).with(TemporalAdjusters.firstDayOfMonth());
//获取天数
LocalDate resultDate = tempDate.plusDays(day - 1);
return resultDate;
}
/**
* 自定义LocalDateTime
* @param year 年
* @param month 月
* @param day 日
* @param hour 时
* @param minute 分
* @param seconds 秒
* @return LocalDateTime
*/
public static LocalDateTime getCustomizeLocalDateTime(Integer year, Integer month, Integer day,
Integer hour, Integer minute, Integer seconds){
//获取自定义天
LocalDate localDate = getLocalDateByYearAndMonthAndDay(year, month, day);
LocalDateTime localDateTime = localDate.atStartOfDay().plusHours(hour).plusMinutes(minute).plusSeconds(seconds);
return localDateTime;
}
LocalDate获取自定义日期
最新推荐文章于 2024-08-05 11:46:31 发布