Friday, July 31, 2009

Calculating the difference between two times in java?

hi, i'v got two times and i want to caculate the differernce between them. they are both Strings so will i have to convert them into milliseconds first or is there a way to do the calculation directly?

Calculating the difference between two times in java?
Here I was thinking that you were asking about two different times on the island of Java, in the Republic of Indonesia. Based on a time zone map, the entire island is in the same time zone, same as Christmas Island, Vietnam, Laos, Cambodia, and Thailand.


http://upload.wikimedia.org/wikipedia/co...





But based on your further description, it seems that you are calculating times within the java computer programming language. That's completely different... I'd probably start with the Java tutorials: http://java.sun.com/
Reply:First you have to do parseInt to get it into an integer and then do the calculation. You can never do a calculation when the number is stored as a string.
Reply:It might not be easiest way, but I'd splint the Strings into integers, create GregorianCalendar objects, convert to longs (milliseconds), and then subtract. Then you've got a bunch of % operations to get back into sensible times.


No comments:

Post a Comment