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 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:15 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();
}
    }
}









Related Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
How to calculate Date Difference in Java?
How to calculate Date Difference in Java?  Hi, I have two dates variable. How to calculate Date Difference in Java? Thanks   Hi, You can use the Calendar class for calculating the date difference in Java. Get data
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
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
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
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
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
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 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
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
This code send email two times but i want only once
This code send email two times but i want only once   public void dbbackup_notify(String email,String data,String subject){ String toEmails = email; Session session=Session.getInstance(props, new
This code send email two times but i want only once
This code send email two times but i want only once   public void dbbackup_notify(String email,String data,String subject){ String toEmails = email; Session session=Session.getInstance(props, new
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
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   
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
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
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
difference
difference  what's the difference between mysql and sql
difference
difference  difference between hashtable and hashtree
difference
difference  difference b/w java and asp.net
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
Difference
Difference  What Is the difference between JDK & SDK
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
difference
difference  difference between thread and process in java   Difference between Process and Thread: 1)Process is a program under execution whereas Thread is a part of program. 2)Process are heavy weight programs which
difference
difference  difference between Method Overloading and method Overriding   Difference between Method Overloading and Method Overriding: Overriding is the concept of having functions of same name and signature
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
Mysql Time Difference Function
difference between any two dates. Understand with ExampleADS_TO_REPLACE_1 The Tutorial... that return you the time difference between any two consecutive dates. TimeDiff... Mysql Time Difference Function     
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
ModuleNotFoundError: No module named 'express'
ModuleNotFoundError: No module named 'express'  Hi, My Python... 'express' How to remove the ModuleNotFoundError: No module named 'express... to install padas library. You can install express python with following command
ModuleNotFoundError: No module named 'Terms'
ModuleNotFoundError: No module named 'Terms'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Terms' How to remove the ModuleNotFoundError: No module named 'Terms'
ModuleNotFoundError: No module named 'Terms'
ModuleNotFoundError: No module named 'Terms'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Terms' How to remove the ModuleNotFoundError: No module named 'Terms'
Version of com.contedevel>express dependency
List of Version of com.contedevel>express dependency
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
How to display a file for 24 hours?
How to display a file for 24 hours?  How to display a file for 24 hours
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
calculate average
calculate average  Question 2 cont.d Test case c: home works/labs 10 9 9 9 10 10 9 9 10 10 9 9 10 test scores: 65 89 note, the program should work with different numbers of home works/labs
sql express connection
sql express connection  Sir, I am using ms-SQL server 2005 as database. i have .mdf file and .ldf database base files with me. How to connect to these files in my web application. I am using type-4 drivers... Please let me know
C Addition of two matrices
C Addition of two matrices In this section, we are going to calculate the sum of  two 2 X 2 matrices containing rows and columns. For this , we need to declare two dimensional array of integer type. Here, we prompt  the user

Ads