Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calculating times (please help!!)

 
Steve Kiernan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to figure out how to take a String "10:23" and a String "11:30" and add the total number of minutes between these two times. ex 67 minutes
These Strings are actually on JLabels
Any help will be greatly appreciated
 
Kris Nelson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I have always done it is to create two java.util.Date objects using the different times. Using each Date object, call the object's getTime() which returns a long value of the number of milliseconds January 1, 1970, 00:00:00 GMT (a.k.a epoch). If you don't care about the dates and just worrying about the times, make the Date objects the same day. Then, simply subtract one long from the other to get the number of milliseconds between them. I think you can figure out how to convert milliseconds into hh:mm:ss etc.

------------------
WebNelly.com
Java/XML Web Development
Check it out!
http://www.webnelly.com
 
Steve Kiernan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kris Nelson:
The way I have always done it is to create two java.util.Date objects using the different times. Using each Date object, call the object's getTime() which returns a long value of the number of milliseconds January 1, 1970, 00:00:00 GMT (a.k.a epoch). If you don't care about the dates and just worrying about the times, make the Date objects the same day. Then, simply subtract one long from the other to get the number of milliseconds between them. I think you can figure out how to convert milliseconds into hh:mm:ss etc.

Sweet!! Thanks man, I knew it had to be simple
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic