Java Long Number to Timestamp timestampToString(long micros)

Here you can find the source of timestampToString(long micros)

Description

Transforms a timestamp into a string, whose formatting and timezone is consistent across Kudu.

License

Apache License

Parameter

Parameter Description
micros the timestamp, in microseconds

Return

a string, in the format: YYYY-MM-DDTHH:MM:SS.ssssssZ

Declaration

public static String timestampToString(long micros) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    private static final ThreadLocal<DateFormat> DATE_FORMAT = new ThreadLocal<DateFormat>() {
        @Override/*from w  w  w. j a va 2s  . c o  m*/
        protected DateFormat initialValue() {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
            return sdf;
        }
    };

    /**
     * Transforms a timestamp into a string, whose formatting and timezone is consistent
     * across Kudu.
     * @param micros the timestamp, in microseconds
     * @return a string, in the format: YYYY-MM-DDTHH:MM:SS.ssssssZ
     */
    public static String timestampToString(long micros) {
        long tsMillis = micros / 1000L;
        long tsMicros = micros % 1000000L;
        String tsStr = DATE_FORMAT.get().format(new Date(tsMillis));
        return String.format("%s.%06dZ", tsStr, tsMicros);
    }
}

Related

  1. timestamp(long time)
  2. timestamp2DataTime(long timestamp)
  3. timestamp2Date(long timestamp, String timezone)
  4. timestamp2DateTime(long t)
  5. timestampToHumanDateAndTime(long timestamp)
  6. timestampToString(long time)
  7. timestampToString(long timestamp)
  8. timeString(long timestamp)
  9. toDateTimeString(long timestamp)