Java Date to Day getDays(Date t, Date baseDate)

Here you can find the source of getDays(Date t, Date baseDate)

Description

Get days difference between two dates

License

Open Source License

Parameter

Parameter Description
t The time
baseDate Base date

Return

The time delta value

Declaration

public static int getDays(Date t, Date baseDate) 

Method Source Code

//package com.java2s;
/* Copyright 2012 Yaqiang Wang,
* yaqiang.wang@gmail.com//w  w  w  .ja v  a2s  .co  m
* 
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
* 
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
* General Public License for more details.
*/

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     * Get days difference between two dates
     *
     * @param t The time
     * @param baseDate Base date
     * @return The time delta value
     */
    public static int getDays(Date t, Date baseDate) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(baseDate);
        long sl = cal.getTimeInMillis();
        long el, delta;
        cal.setTime(t);
        el = cal.getTimeInMillis();
        delta = el - sl;
        int value = (int) (delta / (24 * 60 * 60 * 1000));

        return value;
    }
}

Related

  1. getDayMonthYear(Date aDate, boolean isAddSpace)
  2. getDayNumber(Date startDate, Date endDate)
  3. getDayOfDate(Date date)
  4. getDayOfThisYear(Date currentdate)
  5. getDayOfYear(Date date)
  6. getDaysEarlierDate(int days)
  7. getDayShort(Date date)
  8. getDaysMin(Date d)
  9. getDaysPassedSince(Date dateLastModified)