SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
long to = df.parse("2008-4-25").getTime();
long from = df.parse("2008-1-20").getTime();
System.out.println((to - from) / (1000 * 60 * 60 * 24));
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
long to = df.parse("2008-4-25").getTime();
Calendar to1 = new GregorianCalendar();
to1.setTimeInMillis(to);
//Calendar没有相减的方法,要相减只能把加的数设为负数。
to1.add(Calendar.YEAR, -2008)
to1.add(Calendar.MONTH, -1)
to1.add(Calendar.DAY_OF_MONTH, -20)
两个日期相差的年份 int year=to1.get(Calendar.YEAR);
两个日期相差的月份 int month=to1.get(Calendar.MONTH);
两个日期相差的天数 int day=to1.get(Calendar.DAY_OF_MONTH);