Calculate Time difference in Java

public static long checkTimeDifference(String time1,String time2){
         //time1 and time 2 must be in HH:mm:ss format

    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    Date date1;
    Date date2;
    long difference=0;
try {
date1 = format.parse(time1);
date2 = format.parse(time2);
difference = date2.getTime() - date1.getTime();
} catch (ParseException e) {
return difference;


Popular posts from this blog

Struts 2 - struts tag with boolean property

Android: where to run keytool command in android