public static int getDifference(String ddays) {
SimpleDateFormat mFormat = new SimpleDateFormat("yyyy.MM.dd");
Date d = null;
try {
d = mFormat.parse(ddays);
} catch (ParseException e) {
// TODO Auto-generated catch block
}
Calendar getDay = Calendar.getInstance();
getDay.setTime(d);
getDay.set(Calendar.HOUR_OF_DAY, 0);
getDay.set(Calendar.MINUTE, 0);
getDay.set(Calendar.SECOND,0);
getDay.set(Calendar.MILLISECOND,0);
long getTime = getDay.getTimeInMillis();
Calendar mCalendar = Calendar.getInstance();
mCalendar.set(Calendar.HOUR_OF_DAY, 0);
mCalendar.set(Calendar.MINUTE, 0);
mCalendar.set(Calendar.SECOND,0);
mCalendar.set(Calendar.MILLISECOND,0);
long nowTime = mCalendar.getTimeInMillis();
long diff = (getTime - nowTime);
int oneday = 24 * 60 * 60 * 1000; // ms
int difference = (int) (diff /= oneday);
return difference;
}
※ 일 차이 구하기
int day = getDifference("2016.08.15") 으로 사용 가능
그날의 00시 00분 00초 00밀리초와
오늘의 00시 00분 00초 00밀리초의 차이를 구함