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();
}
Select and right click the cells with time you want to display in minutes and seconds, and then click Format Cells in the right-clicking menu. See screenshot: 2. In the Format Cells dialog box, click Custom in the Category box under Number tab, type [m]:ss into the Type box, and then click the OK button.
In the Format Cells dialog box, click the Number tab. Under Category, click Custom. In the Type box, type [h]:mm. TIP You can also show the results in minutes and seconds by setting the format to [m]:ss, or minutes only by typing [m].
As with Excel, the first step to converting elapsed second to time is to divide the value by 86400. To format the cells for mm:ss, select Format > Number > More Formats > More date and time formats from the Menu.
We express hours (60 minutes) and portions of an hour (minutes) with the format HH:MM. So whenever we see time expressed with a colon (:) we know that we are seeing time in the hours and minutes format. Let's look at a simple example. 7:30 is read as 'seven hours and 30 minutes.
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:
int minutes = time / (60 * 1000);
int seconds = (time / 1000) % 60;
String str = String.format("%d:%02d", minutes, seconds);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With