Java Utililty Methods Day Between

List of utility methods to do Day Between

  1. HOME
  2. Java
  3. D
  4. Day Between

Description

The list of methods to do Day Between are organized into topic(s).

Method

int calculateDayDifference(final Date a, final Date b)
This method calculates the difference between 2 dates.
int tempDifference = 0;
int difference = 0;
Calendar earlier = Calendar.getInstance();
Calendar later = Calendar.getInstance();
if (a.compareTo(b) < 0) {
 earlier.setTime(a);
 later.setTime(b);
} else {
...
long calculateDays(Date beginDate, Date endDate)
Calculates difference between two days, in days
GregorianCalendar beginCalendar = new GregorianCalendar();
beginCalendar.setTime(beginDate);
GregorianCalendar endCalendar = new GregorianCalendar();
endCalendar.setTime(endDate);
java.util.Date d1 = beginCalendar.getTime();
java.util.Date d2 = endCalendar.getTime();
long l1 = d1.getTime();
long l2 = d2.getTime();
...
long calculateDays(Date dateEarly, Date dateLater)
calculate Days
return (dateLater.getTime() - dateEarly.getTime()) / (24 * 60 * 60 * 1000);
String calculateDifference(Date d1, Date d2)
calculate Difference
Calendar startDate = Calendar.getInstance();
Calendar endDate = Calendar.getInstance();
startDate.clear();
endDate.clear();
startDate.setTime(d1);
endDate.setTime(d2);
if ((startDate == null) || (endDate == null) || startDate.after(endDate)) {
 return "";
...
int calculateDifferMonths(Date date1, Date date2, boolean isTruncate)
calculate Differ Months
final int[] bgnDate, endDate;
if (date1.getTime() > date2.getTime()) {
 bgnDate = getYearMonthDay(date2);
 endDate = getYearMonthDay(date1);
} else {
 bgnDate = getYearMonthDay(date1);
 endDate = getYearMonthDay(date2);
final int endMonth;
if (!isTruncate || endDate[2] >= bgnDate[2]) {
 endMonth = endDate[1];
} else {
 endMonth = endDate[1] - 1;
if (endMonth >= bgnDate[1]) {
 return (endDate[0] - bgnDate[0]) * 12 + (endMonth - bgnDate[1]);
} else {
 return (endDate[0] - bgnDate[0] - 1) * 12 + (12 + endMonth - bgnDate[1]);
int calculateNumberOfDays(String dateStr)
calculate Number Of Days
SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_FORMAT);
try {
 Date date = sdf.parse(dateStr);
 Date now = new Date();
 long n1 = now.getTime();
 long n2 = date.getTime();
 if (n1 > n2) {
 long diffTime = n1 - n2;
...
int countDiffDay(String beginDateBase, String endDateBase)
count Diff Day
Calendar beginDate = Calendar.getInstance(Locale.US);
Calendar endDate = Calendar.getInstance(Locale.US);
int year, month, date;
year = Integer.valueOf(beginDateBase.substring(0, 4)).intValue();
if (year > 2400) {
 year = year - 543;
month = Integer.valueOf(beginDateBase.substring(4, 6)).intValue() - 1;
...
int dayDiff(Date d1, Date d2)
Determines the number of days between two dates
long timeDiff = removeTime(d1).getTime() - removeTime(d2).getTime();
return (int) (timeDiff / 86400000);
long dayDiff(Date start, Date end)
day Diff
long day = compareDate(start, end);
if (day == 0) {
 return 0;
if (day > 0) {
 return (day - 1) / 1000 / 60 / 60 / 24 + 1;
} else {
 return (day + 1) / 1000 / 60 / 60 / 24 - 1;
...
int daysDiff(final Date data1, final Date data2)
Get the difference in days of two given dates.
long ini = getCalendarInstance(data1).getTimeInMillis();
long fim = getCalendarInstance(data2).getTimeInMillis();
long nroHoras = (fim - ini) / 1000 / 3600;
int nroDias = (int) nroHoras / 24;
return nroDias;


AltStyle によって変換されたページ (->オリジナル) /