aspose file tools
The moose likes Java in General and the fly likes calculate the seconds Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "calculate the seconds " Watch "calculate the seconds " New topic
Author

calculate the seconds

Per Lovdinger
Ranch Hand

Joined: Jun 11, 2001
Posts: 35
I want to calculate the exact number of seconds between 2 times
in this format: String yyyymmddmmss.
public int secondsBeteen(String fromTime,String toTime)

Anyone that have a good approach for this ?

thanks in advance
Per
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Yes, you have to use DateFormat or better SimpleDateFormat to be able to parse your input and to get a Date. This Date you can put into a Calendar, which has the function getTimeInMillis(). This you have to do for both date values.
It is easy to substract both millis and to calculate seconds from it.
This sounds a bit strange, but in fact it will be not more than 20 lines of code or maybe less. Even much better, than calculating all by yourself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calculate the seconds
 
Similar Threads
How do i convert hh:mm:ss to percentage
Calculating download time
how to calculate minutes and seconds from media file in j2me
Dates..
Displaying seconds in hh:mm:ss format