public static String addDate(String fromDate, String format, int addYear, int addMonth, int addDate, int addHour, int addMinute, int addSecond) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date date = sdf.parse(fromDate);
Calendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.YEAR, +addYear);
cal.add(Calendar.MONTH, +addMonth);
cal.add(Calendar.DATE, +addDate);
cal.add(Calendar.HOUR, +addHour);
cal.add(Calendar.MINUTE, +addMinute);
cal.add(Calendar.SECOND, +addSecond);
SimpleDateFormat sdf2 = new SimpleDateFormat(format);
String toDate = sdf2.format(cal.getTime());
return toDate;
}
1년 후
String addDate(format, "yyyy-MM-dd HH:mm:ss", 1, 0, 0, 0, 0, 0);
10분 후
String addDate(format, "yyyy-MM-dd HH:mm:ss", 0, 0, 0, 0, 10, 0);
'java' 카테고리의 다른 글
메소드 참조 표현식(이중 콜론 연산자), 생성자참조 표현식 (0) | 2023.01.18 |
---|---|
한자리 숫자일대 앞에 0을 붙여준다 (0) | 2021.07.29 |
GZip을 이용한 String 압축 및 해제 (0) | 2019.12.26 |
숫자만 입력되었는지 체크하기 (0) | 2019.03.05 |
용량 계산 (0) | 2017.12.27 |