• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diffrenece between two given times...

 
Rekha Anand
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Marshal
Pie
Posts: 21518
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
Rekha Anand
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!

But then how do I solve it?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic