Results 1 to 2 of 2
  1. #1
    abhay_401 is offline Member
    Join Date
    Oct 2013
    Rep Power

    Default How to display in HH:MM:SS... ?


    I am having two dates with times for example:

    String dateStart = "01/14/2012 09:30:55";
    String dateStop = "01/15/2012 18:25:54";

    SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

    Date d1 = null;
    Date d2 = null;

    d1 = format.parse(dateStart);
    d2 = format.parse(dateStop);

    When I subtract: d2 - d1, I want to show the elapsed time in between the above two dates in the format of HH:MM:SS:
    I want the output something like:
    33:05:01. How can I get in that format..? If anybody is having any idea please help me out...

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: How to display in HH:MM:SS... ?

    Well, I am not certain you can use the HH format because it seems to format modulo 24. So at present, all I can recommend is that you subtract the long values returned by Data.getTime() and compute the hours, mins, and seconds yourself. Remember that getTime returns millisecond granularity. You can use System.printf() to format them yourself. Perhaps someone else on this forum can provide better advice.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. GUI Display
    By modhz in forum New To Java
    Replies: 5
    Last Post: 10-27-2011, 02:53 AM
  2. Replies: 1
    Last Post: 12-01-2010, 06:35 PM
  3. Replies: 1
    Last Post: 05-31-2010, 08:46 AM
  4. Replies: 8
    Last Post: 12-29-2008, 07:12 AM
  5. Replies: 0
    Last Post: 06-28-2008, 09:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts