使用库函数可以计算两个时间的毫秒差值,在转换成天数就可以了。
public class CalDays {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print(calDay(2008, 3, 4, 2001, 5, 23));
}
public static int calDay(int y1, int m1, int d1, int y2, int m2, int d2) {
int result = 0;
Date date1 = new Date(y1, m1, d1); //先转换成日期对象
Date date2 = new Date(y2, m2, d2);
long dis = date1.getTime() - date2.getTime(