File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes calculating times (please help!!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calculating times (please help!!)" Watch "calculating times (please help!!)" New topic
Author

calculating times (please help!!)

Steve Kiernan
Greenhorn

Joined: Nov 07, 2001
Posts: 6
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

Joined: Nov 04, 2001
Posts: 35
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


WebNelly.com<br />Java/XML Web Development<br />Check it out!<br /><a href="http://www.webnelly.com" target="_blank" rel="nofollow">http://www.webnelly.com</a>
Steve Kiernan
Greenhorn

Joined: Nov 07, 2001
Posts: 6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calculating times (please help!!)
 
Similar Threads
session timeout
Comparing two times
Session Timeout Timer Reset
parse date string
Spin circles