Here you can find the source of daysBetween(String from, String to, String form)
public static final int daysBetween(String from, String to, String form)
//package com.java2s; public class Main { public static final int daysBetween(String from, String to, String form) { java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(form, java.util.Locale.KOREA); java.util.Date d1 = null; java.util.Date d2 = null; try {/*from w ww . j a va 2 s . c o m*/ d1 = formatter.parse(from); d2 = formatter.parse(to); } catch (java.text.ParseException e) { return -999; } if (!formatter.format(d1).equals(from)) return -999; if (!formatter.format(d2).equals(to)) return -999; long duration = d2.getTime() - d1.getTime(); if (duration < 0) return -999; return (int) (duration / (1000 * 60 * 60 * 24)); // seconds in 1 day } }