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

voidappendSecondsToDurationString(final StringBuilder sb, final long seconds, final long nanoseconds)
append Seconds To Duration String
if (seconds < 0 && nanoseconds > 0) {
    if (seconds == -1) {
        sb.append("0");
    } else {
        sb.append(Math.abs(seconds + 1));
} else {
    sb.append(Math.abs(seconds));
...
longasNanoSeconds(long seconds)
as Nano Seconds
return (seconds * 1000 + MICROSECONDS_TO_UNIX_EPOCH_FROM_WINDOWS) * 10;
longdoubleToNanoseconds(double d)
double To Nanoseconds
return (long) (d * 1000000000);
floatdurationInSeconds(long startNano)
Returns the duration in second between the specified nano time and now.
final long endNano = System.nanoTime();
final long durationMillis = (endNano - startNano) / 1000000;
final float duration = durationMillis / 1000f;
return duration;
StringhumanReadableNanoseconds(long delta)
human Readable Nanoseconds
if (delta < 10L * 1000) {
    return delta + " nanoseconds";
} else if (delta < 10L * 1000 * 1000) {
    return delta / 1000 + " microseconds";
} else if (delta < 10L * 1000 * 1000 * 1000) {
    return delta / (1000 * 1000) + " milliseconds";
} else {
    return delta / (1000 * 1000 * 1000) + " seconds";
...
StringmicroSecondToStr(int nanos, int meta)
micro Second To Str
if (meta > 6) {
    throw new IllegalArgumentException("unknow useconds meta : " + meta);
String microSecond = "";
if (meta > 0) {
    microSecond = String.valueOf(nanos);
    if (microSecond.length() < meta) {
        int total = meta % 2 == 0 ? meta : meta + 1;
...
longnano()
Get the current time in nano second.
return System.nanoTime();
doublenano2milli(double nano)
Translate from nano (10^-9) to milli (10^-3).
return nano * 1e-6;
longnanoSeconds(long millis)
nano Seconds
return millis * 1000000;
longnanoSecondsToSeconds(final long nanoSeconds)
Reduces nanosecond time to seconds.
return nanoSeconds / NANO_TIME_DIVIDER;