Java Utililty Methods Nano Second Convert

List of utility methods to do Nano Second Convert

Description

The list of methods to do Nano Second Convert are organized into topic(s).

Method

doublenanoToMs(final long nano)
nano To Ms
return nano / 1000000.0;
doublenanoToMsConverter(long time)
nano To Ms Converter
return time / ITER_1M;
intnanoToSec(Long n)
nano To Sec
return (int) (n / 1000000000);
doublenanoToSeconds(double nano)
nano To Seconds
double milli = Math.round(nano / 1000000.0);
return milli / 1000.0;
floatnanoToSecs(final long nanoTime)
nano To Secs
return nanoTime / 1000000000.0f;
StringnanoToStr(long tsp)
nano To Str
return String.format("%tF %<tT.%09d", tsp / 1000000, tsp % 1000000000);
longnowInNanoseconds()
now In Nanoseconds
return System.currentTimeMillis() * 1000000;
intparseNanoseconds(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);
longstringToNanoseconds(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;