How to find difference in time between two Date objects

Posted on 2005-04-09
Last Modified: 2010-03-31
Dear java experts ,
           Can somebody help me find the difference in time inthe form of STRING.
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a dd-MMM-yyyy");

Date Time1=sdf.parse(request.getParameter(time1).trim());
Date Time2=sdf.parse(request.getParameter(time2).trim());

I really want time 2 - time 1 in minutes and that too in STRING.

any help will be very highly apprecaiatted.
Question by:Testsubbu
    1 Comment
    LVL 92

    Accepted Solution

    You can get millisend difference using:

    long msecs = Time2.getTime() - Time1.getTime();

    then divid it to get minutes:

    long mins = msecs / (1000 * 60);

    To convert to a String something like:

    String s = mins+" minutes";

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now