
i need jsp code to find out the difference of two times in format hh:mm:ss and want to round off the result to a hour value.it's very urgent.plz someone help me

<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%
try {
String date1 = "25/04/2012";
String time1 = "11:00 AM";
String date2 = "26/04/2012";
String time2 = "12:15 AM";
String format = "dd/MM/yyyy hh:mm a";
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date dateObj1 = sdf.parse(date1 + " " + time1);
Date dateObj2 = sdf.parse(date2 + " " + time2);
long diff = dateObj2.getTime() - dateObj1.getTime();
double diffInHours = diff / ((double) 1000 * 60 * 60);
out.println(diffInHours+"<br>");
out.println("Hours " + (int)diffInHours+"<br>");
out.println("Minutes " + (diffInHours - (int)diffInHours)*60 );
} catch (ParseException e) {
e.printStackTrace();
}
}
}
The above code parse two times and ouputs the difference between two times in terms of hours.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.