Here you can find the source of diffDates(long starttime, long endtime, int type)
public static long diffDates(long starttime, long endtime, int type)
//package com.java2s; import java.util.*; public class Main { public static long diffDates(long starttime, long endtime, int type) { long result = endtime - starttime; switch (type) { case 1:// w w w . j a va2 s. c om result = result / (1000 * 60 * 60 * 24 * 365); break; case 2: result = result / (1000 * 60 * 60 * 24 * 30); break; case 3: result = result / (1000 * 60 * 60 * 24); break; case 4: result = result / (1000 * 60 * 60); break; case 5: result = result / (1000 * 60); break; case 6: result = result / 1000; break; default: break; } return result; } public static long diffDates(Date startdate, Date enddate, int type) { return diffDates(startdate.getTime(), enddate.getTime(), type); } }