public static void main(String args[]){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date1 = sdf.parse("2010-02-01 00:00:00");
Date date2= sdf.parse("2010-02-15 00:00:00");
long day = (date1.getTime()-date2.getTime())/(24*60*60*1000)>0 ? (date1.getTime()-date2.getTime())/(24*60*60*1000):(date2.getTime()-date1.getTime())/(24*60*60*1000);
System.out.println(day);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
输出为14。