Date日期比对
1 Calendar calendar1 = Calendar.getInstance(); 2 Calendar calendar2 = Calendar.getInstance(); 3 calendar1.set(2007, 01, 10); 4 calendar2.set(2008, 07, 01); 5 long milliseconds1 = calendar1.getTimeInMillis(); 6 long milliseconds2 = calendar2.getTimeInMillis(); 7 long diff = milliseconds2 - milliseconds1; 8 long diffSeconds = diff / 1000; 9 long diffMinutes = diff / (60 * 1000); 10 long diffHours = diff / (60 * 60 * 1000); 11 long diffDays = diff / (24 * 60 * 60 * 1000); 12 System.out.println("\nThe Date Different Example"); 13 System.out.println("Time in milliseconds: " + diff + " milliseconds."); 14 System.out.println("Time in 秒: " + diffSeconds + " seconds."); 15 System.out.println("Time in 分钟: " + diffMinutes + " minutes."); 16 System.out.println("Time in 小时: " + diffHours + " hours."); 17 System.out.println("Time in 天: " + diffDays + " days.");
如果有使用请标明来源:http://www.cnblogs.com/duwenlei/