Java Instant to String timestampToDecimalString(Instant t)

Here you can find the source of timestampToDecimalString(Instant t)

Description

Converts the timestamp to seconds as a floating point (seconds.nano).

License

Open Source License

Parameter

Parameter Description
t the timstamp to transform

Return

the string representation of the timestamp using the decimal format

Declaration

public static String timestampToDecimalString(Instant t) 

Method Source Code


//package com.java2s;

import java.text.DecimalFormat;

import java.time.Instant;

public class Main {
    private static final ThreadLocal<DecimalFormat> NANO_FORMATTER = ThreadLocal
            .withInitial(() -> new DecimalFormat("000000000"));

    /**/*w  w w  .j  av a 2  s .  co m*/
     * Converts the timestamp to seconds as a floating point (seconds.nano).
     *
     * @param t the timstamp to transform
     * @return the string representation of the timestamp using the decimal format
     */
    public static String timestampToDecimalString(Instant t) {
        return t.getEpochSecond() + "." + NANO_FORMATTER.get().format(t.getNano());
    }
}

Related

  1. timestampToLittleEndianString(Instant t, boolean includeYear)