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;
	}


    /**
     * 自定义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;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值