Hi all

Is there any class to store time in easily, without having to store a date too?

We have to create a program for swimming competitions. The swimmers in a match need a time (the time they did swimming the match). So we only need hours, minutes, seconds and milliseconds.

Edit start:
I found the class Time too, but there you have to give in milliseconds since a certain date, which is not easy...
The constructor Time(int hour, int minute, int second) is deprecated...
Edit end.

Thanks in advance
Kenny

Ps: this may seem like a stupid question, but this is an example I found:

import java.util.*;
import java.text.*;
public class Apollo {
   public static void main(String[] args) {
      GregorianCalendar liftOffApollo11 = new GregorianCalendar(1969, Calendar.JULY, 16, 9, 32);
      Date d = liftOffApollo11.getTime();
      DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
      DateFormat df2 = DateFormat.getTimeInstance(DateFormat.SHORT);
      String s1 = df1.format(d);
      String s2 = df2.format(d);
      System.out.println(s1);
      System.out.println(s2);
   }
}

and here you need to give in a date too.

You might want to create your own class.

The classes Date and Time are used to store what the say: Date and Time.
You need to store duration. (duration of race)
You cannot say that a swimmer swimmed for 'Date' object time.

But you can say this:He started swimming at Date start = new Date() and finished at Date finish = new Date() And their difference is the time he made in milliseconds: long time = end.getTime() - start.getTime()

Ok thanks, that's a possible solution.
But isn't there already a class in java that can store just an hour, minutes, seconds and milliseconds?
Edit: Or just minutes, seconds and milliseconds, cause a swimmer probably won't be swimming for an hour or more

Cause it's not actually known, or put in by the user, when the swimmer started, only a time is entered.

I could make a class that can store 4 Integers, but a prefab class would be handy.

Thx, Kenny.

I don't believe there is a class that does what you want.

Also I checked the Time class and I don't believe it is what you want. It is used with sql and it represents time like saying now the time is:
"16:05"

Ok, pitty, but thanks for the help.
Greets, Kenny

This question has already been answered. Start a new discussion instead.