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... ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
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 Sun, 13 Oct 2013 09:57:53 +0200
Organization A noiseless patient Spider
Lines 33
Message-ID <l3djq1$3s5$1@dont-email.me> (permalink)
References <c40d8b94-ebd9-43e4-be96-4bfbb8bb69eb@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Injection-Date Sun, 13 Oct 2013 07:57:53 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="b771b069f8002793a1813bddbe39641a"; logging-data="3973"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Rn6L/MaQEuQfS95OUNwEB"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1
In-Reply-To <c40d8b94-ebd9-43e4-be96-4bfbb8bb69eb@googlegroups.com>
Cancel-Lock sha1:3pvjhBxZKgXQvzyI0Bd6FfKVhao=
Xref csiph.com comp.lang.java.programmer:26319

Show key headers only | 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