This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Diffrenece between two given times... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Diffrenece between two given times..." Watch "Diffrenece between two given times..." New topic

Diffrenece between two given times...

Rekha Anand
Ranch Hand

Joined: Feb 23, 2008
Posts: 36
What will be the logic behind finding the difference between two given times in military format? For egs how can i find the number of hours and minutes between 1730hrs and 0900hrs?

Here is what i guessed....
int startTime = 1730;
int endTime = 900;
int diff = (2400 -1730) + 900; // result was 1570; should be 1530.

Please tell me whatz wrong.

Thanks for your time and consideration.
[ February 23, 2008: Message edited by: Rekha Anand ]
Henry Wong

Joined: Sep 28, 2004
Posts: 20034

Basically, straight addition/subtraction can't be done with the representation that you used. And the reason is because the time representation isn't linear.

For example, 859 and 900 should be 1 minute apart. Yet, if you subtract it, you won't get 1.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rekha Anand
Ranch Hand

Joined: Feb 23, 2008
Posts: 36

But then how do I solve it?
marc weber

Joined: Aug 31, 2004
Posts: 11343

Consider the time represented by "1730." Do you have one-thousand seven-hundred thirty of anything? Not really. But you do have (17 * 60) + 30 of something.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Have you checked out Aspose?
subject: Diffrenece between two given times...
It's not a secret anymore!