我是Android新手,我想为我制作一款新应用。我想使用currentDate子结构两个日期(dd / mm / yyyy)格式。例如,我想查找01/02/2013和currentDate之间的天数差异。我该怎么办?
答案 0 :(得分:20)
SimpleDateFormat dfDate = new SimpleDateFormat("dd/MM/yyyy");
java.util.Date d = null;
java.util.Date d1 = null;
Calendar cal = Calendar.getInstance();
try {
d = dfDate.parse("01/02/2012 ");
d1 = dfDate.parse(dfDate.format(cal.getTime()));//Returns 15/10/2012
} catch (java.text.ParseException e) {
e.printStackTrace();
}
int diffInDays = (int) ((d.getTime() - d1.getTime())/ (1000 * 60 * 60 * 24));
System.out.println(diffInDays);
答案 1 :(得分:1)