Here you can find the source of getDateDiffHour(String begindate, String enddate)
public static long getDateDiffHour(String begindate, String enddate)
//package com.java2s; //License from project: Apache License import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static long getDateDiffHour(String begindate, String enddate) { long minuteDiff = getDateDiffMinute(begindate, enddate); Float hourDiff = (float) (minuteDiff / 60); return hourDiff.intValue(); }/*from ww w .ja v a 2s.c o m*/ public static long getDateDiffMinute(String begindate, String enddate) { SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd kk:mm:ss"); ParsePosition pos1 = new ParsePosition(0); ParsePosition pos2 = new ParsePosition(0); if (begindate.length() == 10) begindate = begindate + " 00:00:00"; if (enddate.length() == 10) enddate = enddate + " 00:00:00"; Date BeginDate = formatter.parse(begindate, pos1); Date EndDate = formatter.parse(enddate, pos2); long dateDiff = EndDate.getTime() - BeginDate.getTime(); Float minuteDiff = (float) (dateDiff / 1000 / 60); return minuteDiff.intValue(); } }