seconds is not hires enough for the shell commands

This commit is contained in:
Doug MacEachern 2005-02-25 01:22:41 +00:00
parent d3306f6b1b
commit 4612d3d5bc
1 changed files with 13 additions and 3 deletions

View File

@ -46,9 +46,19 @@ public class Time extends SigarCommandBase {
return nano / 1000000;
}
private static String format(long t) {
t /= 1000;
return t/60 + ":" + t%60;
private static String format(long elap) {
String fraction = (elap % 1000) + "";
int pad = 3 - fraction.length();
StringBuffer buf = new StringBuffer()
.append(elap / 1000).append('.');
//for example, 15 millseconds formatted as ".015" rather than ".15"
while (pad-- > 0) {
buf.append("0");
}
buf.append(fraction).append(" seconds");
return buf.toString();
}
public static void main(String[] args) throws Exception {