天天看點

LocalDate擷取自定義日期

/**
	 * 自定義年月日
	 * @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;
	}