public long date2Date(String sdate1, String sdate2) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date1 = sdf.parse(sdate1);
Date date2 = sdf.parse(sdate2);
return date2.getTime() / (24 * 60 * 60 * 1000) - date1.getTime()/ (24 * 60 * 60 * 1000);
} catch (ParseException e) {
e.printStackTrace();
return 0;
}
} public static void main(String[] args) {
DateTest dt = new DateTest();
long date = dt.date2Date("2012-4-11", "2012-4-23");
System.out.println("相差:" + date); }