Share on Google+

sonika saha
calculate difference of two times and express it in terms of hours
1 Answer(s)      4 years and 11 months 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

Ads

View Answers

April 27, 2012 at 11:15 AM

<[email protected] import="java.util.*"%>
<[email protected] 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
difference
difference  difference b/w java and asp.net
difference
difference  what's the difference between mysql and sql
difference
difference  difference between hashtable and hashtree
Tutorials

Ads

Advertisement null

Ads