import java.text.SimpleDateFormat;
import java.util.Date;
//String to Date
String str="2020-08-12 17:52:08";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date strToDate=sdf.parse(str); //return : Wed Aug 12 17:52:08 KST 2020
//Date to String
SimpleDateFormat f1 = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat f2 = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat f3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sysdate = new Date(); //return : Wed Aug 12 17:52:08 KST 2020
String sys1=f1.format(sysdate);
String sys2=f2.format(sysdate);
String sys3=f3.format(sysdate);
System.out.println(sys1); //return : 20200812
System.out.println(sys2); //return : 2020-08-12
System.out.println(sys3); //return : 2020-08-12 17:52:08
๋ฐ์ํ