Java Second Format formatTimeSecondsSinceEpoch(final long time, StringBuilder sbuffer)

Here you can find the source of formatTimeSecondsSinceEpoch(final long time, StringBuilder sbuffer)

Description

Convert timestamp to seconds since epoch with 3 decimal places.

License

Apache License

Parameter

Parameter Description
time the time as milliseconds since epoch
sbuffer a StringBuilder used to put the formatted number into

Declaration

public static void formatTimeSecondsSinceEpoch(final long time, StringBuilder sbuffer) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  ww  . j  a  v  a2  s  .  c  o m*/
     * Convert timestamp to seconds since epoch with 3 decimal places.
     *
     * @param time the time as milliseconds since epoch
     * @param sbuffer a StringBuilder used to put the formatted number into
     */
    public static void formatTimeSecondsSinceEpoch(final long time, StringBuilder sbuffer) {
        String timeString = Long.toString(time);
        int len = timeString.length();

        if (len < 3) {
            // Something wrong.  Handle it by just returning the input
            // long as a string.  We prefer this to just crashing in the
            // substring handling.
            sbuffer.append(timeString);
            return;
        }

        sbuffer.append(timeString.substring(0, len - 3));
        sbuffer.append('.');
        sbuffer.append(timeString.substring(len - 3));
    }
}

Related

  1. formatSecondsWithHour(int seconds)
  2. formatTime(Date d, Locale locale, boolean withSeconds)
  3. formatTime(double seconds)
  4. formatTime(float seconds)
  5. formatTimeInSeconds(int v)
  6. formatTimeSpanSeconds(long span)
  7. formatTimeWithOutSeconds(java.util.Date d)
  8. getDHMS(long totalSecond)
  9. getElapsedSeconds(long startTime)