0

Please Help me on this.

I had two duration times in string format: Ex: "10" and "0.30"(actually there are in minutes)

I parsed those values Double and find the find the difference?

But I am getting the output as 9.7 which is wrong I want it as 9.30.. Please suggest

Thanks in advance!

  • If you parse "0.30" to a dobule, it is interpreted as "zero point three". Ten minus "zero point three" is "nine point seven". So you will have to try a different approach – Can't Tell Mar 06 '14 at 09:30
  • 1
    You could do some sophisticated stuff with `Calendar` and `Date`. However, in this example, it should be sufficient to convert the time into *seconds* (`int seconds = minutes*60;`), compute the difference in seconds, and afterwards convert the result back to minutes. EDIT: You should clarify whether `0.3` should mean "0.3 minutes" or "30 seconds". You have to adjust your parsing process according to this – Marco13 Mar 06 '14 at 09:30
  • take look at JodaTimer apis. do you want difference in minutes only? – Adi Mar 06 '14 at 09:32

2 Answers2

1

You can use the Joda-Time Library.Use the Period class from which you can get the difference between two times in terms of hours and minutes.For example refer the second answer to this question

Community
  • 1
  • 1
amudhan3093
  • 740
  • 9
  • 17
0

Convert the double into minutes, Here is the link that can help you Convert the string "8:00" into the minutes (integer value).

Community
  • 1
  • 1