Here you can find the source of getDays(Date from, Date to)
public static long getDays(Date from, Date to)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static long getDays(Date from, Date to) { long s = from.getTime(); long e = to.getTime(); return Math.round(((e - s) / (24 * 60 * 60 * 1000.0))); }//from w ww .ja v a2 s . c o m public static long getDays(String from, String to) { return getDays(parseDate(from), parseDate(to)); } public static String getTime() { java.util.Date dt = new java.util.Date(); java.sql.Timestamp ts = new java.sql.Timestamp(dt.getTime()); String time = ts.toString(); return time.substring(0, 19); } public static Date parseDate(String s) { Calendar c = Calendar.getInstance(); try { int d = Integer.parseInt(s); int year = d / 10000; int month = (d % 10000) / 100; int day = d % 100; c.set(year, month - 1, day); } catch (Exception e) { return null; } return c.getTime(); } }