Home Answers Viewqa JSP-Interview-Questions calculate difference of two times and express it in terms of hours

 
 


sonika saha
calculate difference of two times and express it in terms of hours
1 Answer(s)      a year and a month ago
Posted in : JSP-Interview Questions

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

View Answers

April 27, 2012 at 11:16 AM


<%@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.









Related Pages:
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss...(); } } } The above code parse two times and ouputs the difference between two times in terms
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss...(); } } } The above code parse two times and ouputs the difference between two times in terms
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss...(); } } } The above code parse two times and ouputs the difference between two times in terms
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss...); out.println(diffInHours+"<br>"); out.println("Hours " + (int
calculate difference of two times and express it in terms of hours
calculate difference of two times and express it in terms of hours  i need jsp code to find out the difference of two times in format hh:mm:ss...); out.println(diffInHours+"<br>"); out.println("Hours " + (int
to calculate the difference between two dates in java - Java Beginners
to calculate the difference between two dates in java  to write... / (60 * 1000); // Calculate difference in hours long...; // Calculate difference in seconds long diffSeconds = day / 1000
calculate difference between two dates
calculate difference between two dates  hi, I was actually working on to calculate the number of days between two dates of dd/mm/yyyy format... the difference between the two dates
calculate difference between two time in jsp
calculate difference between two time in jsp  How to calculate difference between two dates
How to calculate attending hours?
How to calculate attending hours?  I need to calculate attending hours of a employee in a day in my project to make their monthly salary . By using work starting time and ending time. How should I do it using Date class? Or any
calculate the time ..
="button" value="Calculate Difference" onclick="calculateTimeElapsed();" />...calculate the time ..  [CODE] Elapsed Time Example... 2 hour and 3 hours whatever...when 10 minutes remaining one popup menu come
Date Difference
Date Difference       This example learns how to make the difference between two dates and how to convert milliseconds into seconds, seconds into minutes, minutes into hours, hours
Javascript calculate number of days between two dates
Javascript calculate number of days between two dates In this tutorial, you will learn how to calculate number of days between two dates.For this, you need... the later one from the earlier one returns the difference in milliseconds
Java Swing Date Difference
Java Swing Date Difference In this tutorial, you will learn how to find the difference between two dates. Here is an example that accepts two dates from... the following method that calculates the date difference in terms of days
calculate total hours by start time and end time in javascript - Ajax
calculate total hours by start time and end time in javascript  hi, i... well. i want to display total hours by using start and end timepicker. pls clarify my doubts. how to calculate total hours by using start and end time field
Total Hours Calculation.
Total Hours Calculation.   Hi,How to calculate the total hours by startime and endtime.not railway time just only normal time.please help. Thanks
Ask date difference
" +curyear + " Thn " ); }   Here is an example that accepts two dates from the user and calculates the date difference in terms of days. import...Ask date difference  Hello, I have a problem about how to calculate
Calculate Month Difference in mysql - SQL
Calculate Month Difference in mysql  hi , i am rahul.Can anybody plz help me.i am calculating month difference in mysql5.0 procedure . i have done coding for it. it's counting difference between months. but what i want
How to calculating time difference bewteen two countries using country name?
How to calculating time difference bewteen two countries using country name?  How to calculate the time difference between two countries. Example if i pass India and America, then the program should return the time difference
method and function difference
method and function difference  so far, I understand that method and function are the same thing... but is there any difference between the two terms? Please explain me if both are different terms. Thanks in advance
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ..., '01/02/2012', 103))   DATEDIFF() in MYSQL always returns the difference
PL/SQL Terms
PL/SQL Terms       SQL SQL is an English like language consisting of commands to store... two or more users to wait indefinitely for a locked resource. First user needs
javascript date difference in days.
javascript date difference in days.   I want to find the difference between two dates in terms of days. I am using javascript. Please help.  ...); document.write("Number of day difference : "+dayDiff); </script> <
javascript date difference in months
javascript date difference in months  How can I find the difference between two dates in terms of months using javascript?   <html>... difference in month : "+monthDiff); </script> </head> </html>
Difference in two dates - Java Beginners
Difference in two dates  Hello there once again........ Dear Sir... on that. The thing is, that I need to find the difference between the two dates in JAVA... the difference between two dates. public class DateDiffDemo { public static
JavaScript Date Difference
; In this section, we are going to determine the difference between two dates... the rounded number to the nearest integer. Following code calculate the difference...;"); document.write("Difference between two dates is :"+   Math.ceil
How to get of lastmodified file list between two times in java?
How to get of lastmodified file list between two times in java?  Hi, here is a code that list the last modified files in a directory between two dates. This is working well but is it possible to do the same thing between two
calculate milliseconds to hh mm ss
calculate milliseconds to hh mm ss  how to calculate milliseconds to hh mm ss ? Actually i wanted to calculate week days and hours from milliseconds... minutes = (seconds / 60) | 0; seconds -= minutes * 60; var hours = (minutes / 60
Hi .Difference between two Dates - Java Beginners
Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very good response.. Can u plz guide me the following Program.... difference between two dates.. I need to display the number of days by Each Month
loop to input multiple points to calculate final distance and speed
loop to input multiple points to calculate final distance and speed  ...) { Scanner input= new Scanner(System.in); System.out.print(" Enter two... is", +distance); System.out.println("The total time is ", time/60, "hours ", time%60
Flex difference
Flex difference  Hi.... please tell me about What is the difference between Flex 2.0 and Flex 3.0? Thanks  Ans: There are some... 2. flex ajax bridge 3. Two newly added component Advanced datagrid and OLAP
how to calculate addition of two distances in feets and inches using objects as functions arguments
how to calculate addition of two distances in feets and inches using objects as functions arguments  how to calculate addition of two distances in feets and inches using objects as functions arguments in java
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
How to calculate area of rectangle
rectangle method which takes two parameters of type integer. To calculate the area... How to Calculate Area of Rectangle       In this section we will learn how to calculate area
how to calculate max and min - RUP
how to calculate max and min  hye!i'm a new for the java and i want to ask a question . Could anyone help me to teach how to calculate the maximum and minimum using java language.  Hi friend, In Math class having two
Write a program that makes use of a class called Employee that will calculate an employee's weekly paycheque.
Write a program that makes use of a class called Employee that will calculate... of a class called Employee that will calculate an employee's weekly paycheque. Design... an hourly rate for the number of hours worked (overtime is time and a half for hours
Mysql Time Difference Function
difference between any two dates. Understand with Example The Tutorial describe... the time difference between any two consecutive dates. TimeDiff('Year1 Time1... Mysql Time Difference Function     
Design Express Realization Mode
Design Express Realization Mode       When we want to express our realization, we need a expression... ellipse tool (U key) and draw like two egg shape for eyes and fill white color
difference b/w == and equals()
difference b/w == and equals()  what is the difference between == operator and equals()   Hi Friend, The == operator checks if the two objects were actually the same object. This operator looks at the actually memory
javascript date difference in years
year difference by subtracting the two...javascript date difference in years  I want to find the difference between two dates with respect to years. I am using javascript. Please help.  
what is difference between one-way data binding and two-way data binding?
what is difference between one-way data binding and two-way data binding?  what is difference between one-way data binding and two-way data binding? Thanks
Difference between forward and sendRedirect
Difference between forward and sendRedirect  What's the difference between forward and sendRedirect?   RequestDispatcher.forward() and HttpServletResponse.sendRedirect() are the two methods available for URL redirecting
difference
difference  difference between hashtable and hashtree
difference
difference  what's the difference between mysql and sql
difference
difference  difference b/w java and asp.net
Difference
Difference  What Is the difference between JDK & SDK
Sum of two Matrix
Sum of  two Matrix       In this section, we are going to calculate the sum of two matrix... to this. In this program we are going to calculate the sum of two matrix. To make this program
difference
difference    what is the difference between the JDBC-ODBC bridge, the Native-API-Partly-Java driver, and the JDBC-Net-All-Java Driver is the placement of the database access libraries   Please visit the following link

Ask Questions?

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.