问题
How can I convert a long int of seconds to the human readable format
MM:SS
Only SS should be 0 padded so
long = 67 -> 1:07
回答1:
String readable = String.format("%d:%02d", s/60, s%60);
回答2:
Use integer division by 60 to turn seconds in to whole minutes. The Modulus(%) of seconds by 60 will give the "leftover" seconds. Then use a string conversion to check for the necessity of 0 padding.
int minutes = (total / 60);
int seconds = (total % 60);
String secs = Integer.toString(seconds);
if (seconds < 10) {
secs = "0" + seconds;
}
String time = minutes + ":" + secs;
回答3:
int duration = 90;
int min = duration/60;
int sec = duration%60;
String formattedTime = String.format("%d:%02d",min,sec);
回答4:
Some arithmetic :
long min = value / 60;
long second = value % 60 ;
String value = min + ":" + (second > 10 ? "" : "0") + second;
来源:https://stackoverflow.com/questions/24064759/converting-seconds-to-human-readable-format-mmss-java