Here you can find the source of getApartDate(Date startDate, Date endDate)
public static int getApartDate(Date startDate, Date endDate)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int getApartDate(Date startDate, Date endDate) { Calendar sd = Calendar.getInstance(); Calendar ed = Calendar.getInstance(); sd.setTime(startDate);/*from ww w . j a v a 2 s. c o m*/ int day1 = sd.get(Calendar.DAY_OF_YEAR); ed.setTime(endDate); int day2 = ed.get(Calendar.DAY_OF_YEAR); sd = null; ed = null; return (day2 - day1) + 1; } }