str.append(sec);\r
String ns = formatNs(time, resolution);\r
if (!ns.equals("")) { //$NON-NLS-1$\r
- str.append(':');\r
+ str.append('.');\r
str.append(ns);\r
}\r
\r
\r
// format time from nanoseconds to calendar time HH:MM:SS\r
String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
- str.append(stime + " "); //$NON-NLS-1$\r
+ str.append(stime);\r
+ str.append('.');\r
// append the Milliseconds, MicroSeconds and NanoSeconds as specified in\r
// the Resolution\r
str.append(formatNs(time, res));\r
* @return the formatted nanosec\r
*/\r
public static String formatNs(long time, Resolution res) {\r
- StringBuffer temp = new StringBuffer();\r
+ StringBuffer str = new StringBuffer();\r
boolean neg = time < 0;\r
if (neg) {\r
time = -time;\r
// String strVal = String.format("%09d", time);\r
// String tmp = strVal.substring(strVal.length() - 9);\r
\r
- // number of segments to be included\r
- int segments = 0;\r
- switch (res) {\r
- case MILLISEC:\r
- segments = 1;\r
- break;\r
- case MICROSEC:\r
- segments = 2;\r
- break;\r
- case NANOSEC:\r
- segments = 3;\r
- break;\r
- default:\r
- break;\r
- }\r
-\r
long ns = time;\r
ns %= 1000000000;\r
if (ns < 10) {\r
- temp.append("00000000"); //$NON-NLS-1$\r
+ str.append("00000000"); //$NON-NLS-1$\r
} else if (ns < 100) {\r
- temp.append("0000000"); //$NON-NLS-1$\r
+ str.append("0000000"); //$NON-NLS-1$\r
} else if (ns < 1000) {\r
- temp.append("000000"); //$NON-NLS-1$\r
+ str.append("000000"); //$NON-NLS-1$\r
} else if (ns < 10000) {\r
- temp.append("00000"); //$NON-NLS-1$\r
+ str.append("00000"); //$NON-NLS-1$\r
} else if (ns < 100000) {\r
- temp.append("0000"); //$NON-NLS-1$\r
+ str.append("0000"); //$NON-NLS-1$\r
} else if (ns < 1000000) {\r
- temp.append("000"); //$NON-NLS-1$\r
+ str.append("000"); //$NON-NLS-1$\r
} else if (ns < 10000000) {\r
- temp.append("00"); //$NON-NLS-1$\r
+ str.append("00"); //$NON-NLS-1$\r
} else if (ns < 100000000) {\r
- temp.append("0"); //$NON-NLS-1$\r
+ str.append("0"); //$NON-NLS-1$\r
}\r
- temp.append(ns);\r
-\r
- StringBuffer str = new StringBuffer();\r
- if (segments > 0) {\r
- // append ms\r
- str.append(temp.substring(0, 3));\r
+ str.append(ns);\r
+\r
+ if (res == Resolution.MILLISEC) {\r
+ return str.substring(0, 3);\r
+ } else if (res == Resolution.MICROSEC) {\r
+ return str.substring(0, 6);\r
+ } else if (res == Resolution.NANOSEC) {\r
+ return str.substring(0, 9);\r
}\r
- if (segments > 1) {\r
- // append Micro secs\r
- str.append("."); //$NON-NLS-1$\r
- str.append(temp.substring(3, 6));\r
- }\r
- if (segments > 2) {\r
- // append Nano seconds\r
- str.append("."); //$NON-NLS-1$\r
- str.append(temp.substring(6));\r
- }\r
-\r
- return str.toString();\r
+ return ""; //$NON-NLS-1$\r
}\r
\r
static public int loadIntOption(String opt, int def, int min, int max) {\r