Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Countdown Text Builder
StringBuilder sb = new StringBuilder();
if (secondsRemaining >= 3600) { // over and hour
long hours = secondsRemaining / 3600;
secondsRemaining %= 3600;
sb.append(hours);
sb.append(":");
if (secondsRemaining < 60) {
sb.append("00:"); // we will skip the minutes stuff, so add it here.
}
}
if (secondsRemaining >= 60) { // over a minute
long minutes = secondsRemaining / 60;
secondsRemaining %= 60;
if (minutes > 9) {
sb.append(minutes);
} else {
sb.append(0).append(minutes);
}
sb.append(":");
}
if (secondsRemaining >= 0) {
if (secondsRemaining > 9) {
sb.append(secondsRemaining);
} else {
sb.append(0).append(secondsRemaining);
}
}
timerTextView.setText(sb.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.