String으로 된 날짜에 일자를 더해서 세팅

package com.blue.controller;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class CalendarEx2 { 

       public static void main(String[] arg) { 

             // 2019.12.31 + 2일
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
             Date date = null;
             try {
                    date = dateFormat.parse("20191231");
             } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
             }

             Calendar cal = Calendar.getInstance();
             cal.setTime(date);
             cal.add(Calendar.DATE, 2);
             System.out.println(date);
             System.out.println(cal.getTime());
            

             String strDate = dateFormat.format(cal.getTime());
             System.out.println(strDate);
 

       }


}
Posted by 홍반장水 홍반장水

댓글을 달아 주세요