Here you can find the source of dateSpan(Date beginDate, Date endDate)
public static int[] dateSpan(Date beginDate, Date endDate)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { public static int[] dateSpan(Date beginDate, Date endDate) { Calendar b_cal = Calendar.getInstance(); b_cal.setTime(beginDate);//from ww w. j a va 2 s.co m Calendar e_cal = Calendar.getInstance(); e_cal.setTime(endDate); int year = e_cal.get(Calendar.YEAR) - b_cal.get(Calendar.YEAR); int month = e_cal.get(Calendar.MONTH) - b_cal.get(Calendar.MONTH); if (month < 0 && year > 0) { year--; month += 12; } int day = e_cal.get(Calendar.DATE) - b_cal.get(Calendar.DATE); if (day < 0 && month > 0) { month--; day += 30; } int hour = e_cal.get(Calendar.HOUR) - b_cal.get(Calendar.HOUR); if (hour < 0 && day > 0) { day--; hour += 24; } int minute = e_cal.get(Calendar.MINUTE) - b_cal.get(Calendar.MINUTE); if (minute < 0 && hour > 0) { hour--; minute += 60; } int second = e_cal.get(Calendar.SECOND) - b_cal.get(Calendar.SECOND); if (second < 0 && minute > 0) { minute--; second += 60; } int[] ymdhms = new int[6]; ymdhms[0] = year; ymdhms[1] = month; ymdhms[2] = day; ymdhms[3] = hour; ymdhms[4] = minute; ymdhms[5] = second; return ymdhms; } }