I need to format seconds and minutes from milliseconds. I am using countdownTimer. does anyone have sugestions? I looked at joda time. But all i need is a format so i have 1:05 and not 1:5. thanks
private void walk() {
new CountDownTimer(15000, 1000) {
@Override
public void onFinish() {
lapCounter++;
lapNumber.setText("Lap Number: " + lapCounter);
run();
}
@Override
public void onTick(long millisUntilFinished) {
text.setText("Time left:" + millisUntilFinished/1000);
}
}.start();
}
A real lazy way of doing this as long as you know you won't have more than 60 minutes is to just make a date and use
SimpleDateFormat
i'd use
You could do it using the standard Date formatting classes, but that might be a bit heavy-weight. I would just use the String.format method. For example:
I used Apache Commons StopWatch class. The default output of it's toString method is ISO8601-like, hours:minutes:seconds.milliseconds.
Example of Apache StopWatch