I am wondering what is the best method to convert a time string in the format 00:00:00 to integer or long? My ultimate goal is to be able to convert a bunch of time strings to integers / longs, add them to the array and find the most recent time in the array ...
I would be grateful for any help, thanks!
Well, based on the answers, I decided to go and compare the strings directly. However, I have a problem. It is possible to have more than one "last" time, that is, if two times are equal. If so, I want to add the index of both of these times to an ArrayList. Here is my current code:
days[0] = "15:00:00";
days[1] = "17:00:00";
days[2] = "18:00:00";
days[3] = "19:00:00";
days[4] = "19:00:00";
days[5] = "15:00:00";
days[6] = "13:00:00";
ArrayList<Integer> indexes = new ArrayList<Integer>();
String curMax = days[0];
for (int x = 1; x < days.length1; x++) {
if (days[x].compareTo(curMax) > 0) {
curMax = days[x];
indexes.add(x);
System.out.println("INDEX OF THE LARGEST VALUE: " + x);
}
}
However, this adds indexes 1, 2, and 3 to the ArrayList ...
Can anybody help me?