Skip to content

Instantly share code, notes, and snippets.

@JayNewstrom
Created April 9, 2014 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayNewstrom/10305041 to your computer and use it in GitHub Desktop.
Save JayNewstrom/10305041 to your computer and use it in GitHub Desktop.
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