Here you can find the source of getDaysBetween(int dateInt1, int dateInt2)
Parameter | Description |
---|---|
dateInt1 | first date (integer) |
dateInt2 | second date (integer) |
public static int getDaysBetween(int dateInt1, int dateInt2)
//package com.java2s; import java.util.*; public class Main { private static final long MillisPerDay = (24 * 60 * 60 * 1000); private static HashMap<Integer, Calendar> ctcMemo = new HashMap<>(); /**// w ww .j a v a2 s . c o m * gets days between any two dates (integer form) regardless of order * * @param dateInt1 first date (integer) * @param dateInt2 second date (integer) * @return number of days between dates */ public static int getDaysBetween(int dateInt1, int dateInt2) { Calendar di1 = convertToCal(dateInt1); Calendar di2 = convertToCal(dateInt2); return Math.round(Math.abs(di1.getTimeInMillis() - di2.getTimeInMillis()) / (float) MillisPerDay); } /** * converts dateInt to Calendar * * @param dateInt date int to convert * @return calendar value */ private static Calendar convertToCal(int dateInt) { Calendar result = ctcMemo.get(dateInt); if (result != null) { return result; } Calendar gc = new GregorianCalendar(); gc.setTime(convertToDate(dateInt)); ctcMemo.put(dateInt, gc); return gc; } /** * converts dateInto to date * * @param dateInt dateInt to be converted * @return date */ public static Date convertToDate(int dateInt) { @SuppressWarnings("deprecation") Date nd = new Date(dateInt / 10000 - 1900, (dateInt / 100) % 100 - 1, dateInt % 100); return nd; } }