场景:
前端传输日期如:"2021-01-28 11:08:11"给后端,后端拿到数据后拆分为年、月、日、时、分、秒分别set到不同属性。
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(localUserModel.getExpireTime());
SimpleDateFormat year = new SimpleDateFormat("yyyy");
localUserModel.setExpireYear(Integer.valueOf(year.format(date)));
SimpleDateFormat month = new SimpleDateFormat("MM");
localUserModel.setExpireMonth(Integer.valueOf(month.format(date)));
SimpleDateFormat day = new SimpleDateFormat("dd");
localUserModel.setExpireDay(Integer.valueOf(day.format(date)));
SimpleDateFormat hour = new SimpleDateFormat("HH");
localUserModel.setExpireHour(Integer.valueOf(hour.format(date)));
SimpleDateFormat minute = new SimpleDateFormat("mm");
localUserModel.setExpireMin(Integer.valueOf(minute.format(date)));