List of utility methods to do Nano Second Convert
double | nanoToMs(final long nano) nano To Ms return nano / 1000000.0;
|
double | nanoToMsConverter(long time) nano To Ms Converter return time / ITER_1M;
|
int | nanoToSec(Long n) nano To Sec return (int) (n / 1000000000); |
double | nanoToSeconds(double nano) nano To Seconds double milli = Math.round(nano / 1000000.0); return milli / 1000.0; |
float | nanoToSecs(final long nanoTime) nano To Secs return nanoTime / 1000000000.0f;
|
String | nanoToStr(long tsp) nano To Str return String.format("%tF %<tT.%09d", tsp / 1000000, tsp % 1000000000); |
long | nowInNanoseconds() now In Nanoseconds return System.currentTimeMillis() * 1000000;
|
int | parseNanoseconds(String s) parse Nanoseconds if (s == null) { return 0; } else if (s.length() < 9) { return Integer.parseInt(s + "000000000".substring(s.length())); } else { return Integer.parseInt(s); |
long | stringToNanoseconds(String time) Convert a string representing a time to the corresponding long. long result = 0L; StringBuffer buffer = new StringBuffer(time); try { int dot = buffer.indexOf("."); if (dot == -1) { buffer.insert(0, "."); dot = 0; for (int i = buffer.length() - dot - 1; i < 9; i++) buffer.append("0"); int nbDecimals = buffer.substring(dot + 1).length(); if (nbDecimals > 9) buffer.delete(buffer.substring(0, dot + 1 + 9).length(), buffer.length()); long seconds = (dot > 0) ? Long.parseLong(buffer.substring(0, dot)) : 0; seconds = Math.abs(seconds); long nanosecs = Long.parseLong(buffer.substring(dot + 1)); result = seconds * 1000000000 + nanosecs; } catch (NumberFormatException e) { return result; |