[ Java ] JAVA에서 날짜구하기(date, simple date format)


Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
System.out.println("현재날짜 : "+ sdf.format(date));

Calendar cal = Calendar.getInstance();
cal.add(cal.DATE, -7);
Date predate = cal.getTime();
System.out.println("pre날짜 : "+ sdf.format(predate));

결과값은 ex) 20190408 / 20190401





© 2018. by sora

Powered by sora