Here you can find the source of getDurationHour(Timestamp time1, Timestamp time2, String direction)
public static String getDurationHour(Timestamp time1, Timestamp time2, String direction)
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.DecimalFormat; public class Main { public static String getDurationHour(Timestamp time1, Timestamp time2, String direction) { String f = direction;/*from w ww . ja va 2 s . com*/ if (f == null) { f = "+"; } long ctime1 = System.currentTimeMillis(); long ctime2 = System.currentTimeMillis(); if (time1 != null) { ctime1 = time1.getTime(); } if (time2 != null) { ctime2 = time2.getTime(); } int dur = 0; if ("+".equals(f)) {// time2-time1 dur = (int) (((ctime2 - ctime1) / 1000) / 60);// min } else { dur = (int) (((ctime1 - ctime2) / 1000) / 60);// min } double dur_hour = (double) dur / 60; DecimalFormat format = new DecimalFormat("###.##"); return format.format(dur_hour) + "hr"; } }