sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | |
sitelink4 | |
sitelink5 | |
sitelink6 |
예를 들어, 1월31일의 다음날은 2월1일이다
1. Calendar.add 함수 이용
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
cal.setTime(sdf.parse("20210131"));
cal.add(Calendar.DAY_OF_MONTH, 1);
int yyyy = cal.get(Calendar.YEAR);
int mm = cal.get(Calendar.MONTH) + 1;
int dd = cal.get(Calendar.DAY_OF_MONTH);
System.out.println(" added -- " + yyyy + (mm > 9 ? mm : "0" + mm) + (dd > 9 ? dd : "0" + dd));
출력 결과는 "20210201"
2. Date.setTime 함수 이용
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Calendar date = Calendar.getInstance();
date.setTime(sdf.parse("20210131"));
long nTime = date.getTimeInMillis() + 86400000;
Date d = new Date();
d.setTime(nTime);
date.setTime(d);
StringBuffer outDate = new StringBuffer();
outDate.append(date.get(Calendar.YEAR));
outDate.append("." + (date.get(Calendar.MONTH) + 1));
outDate.append("." + date.get(Calendar.DAY_OF_MONTH));
System.out.println(outDate.toString());
출력 결과는 "2021.2.1"