Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


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


Advertisement
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 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   
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   
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
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
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
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
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
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
How to display a file for 24 hours?
How to display a file for 24 hours?  How to display a file for 24 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     
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
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
How to learn hibernate in 24 hours?
How to learn hibernate in 24 hours?  Hi, I am assigned a new project and after 2 days I have to start working on it. I have 48 hours with me. I will spend 24 hours from 48 hours. I want to learn Hibernate in just 24 hours
Oracle 10g Express Edition - IDE Questions
Oracle 10g Express Edition  Do we need internet connection to work with oracle10g Express Edition
Java add hours to Date
Java add hours to Date In this tutorial, you will learn how to add hours... used in date time manipulation. Here, we are going to add few hours to current...() of Calendar class, we have added 4 hours to the calendar which in result display
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
cache refresh after 24 hours
cache refresh after 24 hours  I have developed an application which uses websphere application server 6.1 which needs to query the database(oracle) after every 24 hours periodically.But it is not getting executed properly because
calculate average
calculate average   Design and write a java program to determine all three digit numbers such that the sum of the cubes of the digits is equal... and write a program and calculate your final average in this course. The details
how to print of hours and minutes of 8725 seconds
how to print of hours and minutes of 8725 seconds  how to print of hours and minutes of 8725 seconds
how many hours and minutes in 8725 seconds
how many hours and minutes in 8725 seconds  how many hours and minutes in 8725 seconds? Thanks
 

 

 

DMCA.com