2012-09-17 10:44:54
2012-09-15 10:44:54
这两个日期 怎么求他们之间差几天
代码
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class mydate {
public static void main(String[] args){
Calendar calendar=Calendar.getInstance();
Date date=calendar.getTime();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(df.format(date));
Calendar riqi=Calendar.getInstance();
riqi.set(2012, 8, 15);
Date rizi=riqi.getTime();
System.out.println(df.format(rizi));
}
}
------解决方案--------------------------------------------------------
(date.getTime()-rizi.getTime()) / (3600 * 24 * 1000)
------解决方案--------------------------------------------------------
System.out.println((date.getTime() - rizi.getTime()) / 1000 / 60 / 60 / 24 + 1);