Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26319

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

From Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How to display in HH:MM:SS... ?
Date 2013-10-13 09:57 +0200
Organization A noiseless patient Spider
Message-ID <l3djq1$3s5$1@dont-email.me> (permalink)
References <c40d8b94-ebd9-43e4-be96-4bfbb8bb69eb@googlegroups.com>

Show all headers | View raw


On 2013-10-10 19:58, abhilash.androiddeveloper@gmail.com allegedly wrote:
> Hi,
> 
> 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 ela[sed time in between the above two dates in the format in HH:MM:SS: like 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... 
> 

public static String computeDiffTimeAsString( Date d1, Date d2 ){
  if( d1.after( d2 ) ) throw new IllegalArgumentException(
String.format( "Start date %tc is after end date %tc", d1, d2 ) );

  long secs = (d2.getTime() - d1.getTime()) / 1000;
  return String.format( "%2d:%2d:%2d", secs / 3600, secs % 3600 / 60,
secs % 60 );
}

(Caveat: neither compiled nor tested)

-- 
DF.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to display in HH:MM:SS... ? abhilash.androiddeveloper@gmail.com - 2013-10-10 10:58 -0700
  Re: How to display in HH:MM:SS... ? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-10-13 09:57 +0200
  Re: How to display in HH:MM:SS... ? Arne Vajhøj <arne@vajhoej.dk> - 2013-10-19 22:23 -0400

csiph-web