Here you can find the source of diffHour(String day1, String day2)
public static int diffHour(String day1, String day2) throws ParseException
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat dayParse = new SimpleDateFormat("yyyy-MM-dd"); private static SimpleDateFormat seconParse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static int diffHour(String day1, String day2) throws ParseException { Date parse = seconParse.parse(day1); Date parse2 = dayParse.parse(day2); long time = parse.getTime(); long time2 = parse2.getTime(); long diffTimes = time2 - time; int hours = (int) (diffTimes / 1000 / 60 / 60); return hours; }/* w w w . ja va2 s . c o m*/ }