Dear GWT Group,
Is there code that already exists or do you have another suggestion in
formatting a seconds value into a stopwatch style string?
// Example call:
String stopwatch = buildStopwatch(350);
// returns 00:05:50
private String formatDigits(int s) {
if(s < 10) {
return "0" + Integer.toString(s);
} else {
return Integer.toString(s);
}
}
// Pass seconds. Returns 00:00:00 stop watch format.
private String buildStopwatch(int s) {
if (s < 60) {
return "00" + ":" + "00" + ":" + formatDigits(s);
}
int minutes = s / 60;
int seconds = s % 60;
if (minutes < 60) {
return "00" + ":" + formatDigits(minutes) + ":" +
formatDigits
(seconds);
}
int hours = minutes / 60;
minutes = hours % 60;
return formatDigits(hours) + ":" + formatDigits(minutes) + ":" +
formatDigits(seconds);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---