parsing stopwatch data

I need to parse stopwatch data from a textfile in a beautifull way.

Data is represented in a "5.25.12" way, where 5 stands for 5 minutes, 25 stands for 25 seconds and 12 stands for 120 milliseconds.

Is there a way to parse such a date with a SimpleDateFormat?

I tried to do so using "mm.ss.SSS" pattern, but failed (result was a negative value).

1) is it possible to parse "5.25.12" data by using SimpleDateFormat?

1a) which pattern should I use to parse such a string to date?

2) May be there is a more beautiful way to parse such a data?

Message was edited by:

Nikita_Koselev

[633 byte] By [Nikita_Koseleva] at [2007-11-27 5:59:36]
# 1
can you explain with simple example?
AnanSmritia at 2007-7-12 16:36:22 > top of Java-index,Java Essentials,Java Programming...
# 2

The pattern you give is valid and using it you can construct a SimpleDateFormat which will convert a String like "5.25.12" into a date whose toString() representation is like "Thu Jan 01 00:05:25 NZST 1970".

Note: you get 12 milliseconds, not 120. If your data records centiseconds you may have to add a zero. Also it does give a date. If you are more interested in an interval of time you could split() the string and use the components separately.

pbrockway2a at 2007-7-12 16:36:22 > top of Java-index,Java Essentials,Java Programming...
# 3

private SimpleDateFormat minutesAndSecondsFormat = new SimpleDateFormat("mm.ss.SSS", new Locale(localeName));

double run1500meters = minutesAndSecondsFormat.parse(((String) athletesList.get(10)).trim()).getTime();

if athletesList.get(10) is "5.25.12" getTime()

returns -6874988.

Nikita_Koseleva at 2007-7-12 16:36:22 > top of Java-index,Java Essentials,Java Programming...
# 4
It seems I understood, why value was negative. I'm in estonia, so my time was EST. getTime() "Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object." So getTime() returns 325 - 7200 seconds.
Nikita_Koseleva at 2007-7-12 16:36:22 > top of Java-index,Java Essentials,Java Programming...
# 5

> It seems I understood, why value was negative. I'm in estonia

I got the value -42874988 and had just figured out it was 12 hours different from what I expected. I'm not as quick as you so I hadn't twigged to the fact that I'm 12 hours ahead of GMT.

There's my thing learnt for the day. Thanks!

pbrockway2a at 2007-7-12 16:36:22 > top of Java-index,Java Essentials,Java Programming...