Java Instant to String timestampToLittleEndianString(Instant t, boolean includeYear)

Here you can find the source of timestampToLittleEndianString(Instant t, boolean includeYear)

Description

Transforms the timestamp to string, using the format HH:mm:ss.SSS MMM dd (yyyy).

License

Open Source License

Parameter

Parameter Description
t the timestamp to transform
includeYear true if the year should included in the format

Return

string representation of the timestamp using the above format

Declaration

public static String timestampToLittleEndianString(Instant t, boolean includeYear) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.time.Instant;

import java.util.Date;

public class Main {
    private static final ThreadLocal<DateFormat> LE_TIMESTAMP_FORMATTER = ThreadLocal
            .withInitial(() -> new SimpleDateFormat("HH:mm:ss.SSS MMM dd"));
    private static final ThreadLocal<DateFormat> SLE_TIMESTAMP_FORMATTER = ThreadLocal
            .withInitial(() -> new SimpleDateFormat("HH:mm:ss.SSS MMM dd yyyy"));

    /**//from w w  w  . jav a 2  s  .c o  m
     * Transforms the timestamp to string, using the format HH:mm:ss.SSS MMM dd (yyyy).
     *
     * @param t the timestamp to transform
     * @param includeYear true if the year should included in the format
     * @return string representation of the timestamp using the above format
     */
    public static String timestampToLittleEndianString(Instant t, boolean includeYear) {
        if (t == null) {
            return null;
        }
        return includeYear ? SLE_TIMESTAMP_FORMATTER.get().format(Date.from(t))
                : LE_TIMESTAMP_FORMATTER.get().format(Date.from(t));
    }
}

Related

  1. timestampToDecimalString(Instant t)