Here you can find the source of getDateDiff(Calendar d1, Calendar d2)
Parameter | Description |
---|---|
d1 | the first Date |
d2 | the second Date |
public static long getDateDiff(Calendar d1, Calendar d2)
//package com.java2s; /*/*w w w . j a va2 s . c o m*/ Animal Shelter Manager Copyright(c)2000-2011, R. Rawson-Tetley This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. Contact me by electronic mail: bobintetley@users.sourceforge.net */ import java.util.Calendar; public class Main { /** * Computes the number of minutes between * two Dates. * * @param d1 the first Date * @param d2 the second Date * * @return the absolute value of the number * of minutes * * @exception NullPointerException if either * Date null */ public static long getDateDiff(Calendar d1, Calendar d2) { //assert d1 != null && d2 != null; if ((d1 == null) || (d2 == null)) { throw new NullPointerException("d1 or d2 null"); } // get the difference in milliseconds and // take the absolute value long diff = d1.getTime().getTime() - d2.getTime().getTime(); // convert milliseconds to seconds // and then to minutes long res = diff / (1000 * 60); return res; } }