반응형
→ 오늘 날짜 yyyy/MM/dd 형식으로 나타내기
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String toDay = sdf.format(date);
toDay.replaceAll("-", "/");
결과 : 2016/09/28
→ 오늘로부터 2달 전 날짜 구하기
Calendar cal = new GregorianCalendar(Locale.KOREA);
cal.setTime(date);
cal.add(Calendar.MONTH, -2);
String twoMonthAgo = sdf.format(cal.getTime());
twoMonthAgo.replaceAll("-", "/");
결과 : 2016/07/28
날짜 관련하여서 필요한데로 커스터마이징이 필요한 경우 하기 사이트 참고하여서 개발하세요~
http://betatester.tistory.com/16
반응형
'Java' 카테고리의 다른 글
PKIX path building failed 오류 해결법 (0) | 2017.09.27 |
---|---|
javax.persistence.xxx 가 무엇인가 ? (0) | 2016.11.11 |
자바 컬렉션 List, Map, Vector 입력 출력 (0) | 2016.10.04 |
HttpURLConnection클래스로 웹페이지 POST 호출 방법 (0) | 2016.09.29 |
서버 호출로 jqGrid(JSON)구현 시 참고 (0) | 2016.09.28 |