Here you can find the source of getHours(Date t, Date baseDate)
Parameter | Description |
---|---|
t | The time |
baseDate | Base date |
public static int getHours(Date t, Date baseDate)
//package com.java2s; /* Copyright 2012 Yaqiang Wang, * yaqiang.wang@gmail.com/*from w w w . ja v a2 s. 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 hours difference between two dates * * @param t The time * @param baseDate Base date * @return The time delta value */ public static int getHours(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 / (60 * 60 * 1000)); return value; } }