Java Time Format formatTimestampForLogging(final long rawNanosTimestamp)

Here you can find the source of formatTimestampForLogging(final long rawNanosTimestamp)

Description

format Timestamp For Logging

License

Open Source License

Declaration

public static String formatTimestampForLogging(final long rawNanosTimestamp) 

Method Source Code

//package com.java2s;
/**/*from   w w  w . j  av  a 2  s.  co  m*/
 *
 * Copyright (C) 2015 - Daniel Hams, Modular Audio Limited
 *                      daniel.hams@gmail.com
 *
 * Mad is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Mad is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Mad.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    public static String formatTimestampForLogging(final long rawNanosTimestamp) {
        final long nanosPart = rawNanosTimestamp % 1000;
        final long totalMicros = rawNanosTimestamp / 1000;
        final long microsPart = totalMicros % 1000;
        final long totalMillis = totalMicros / 1000;
        final long millisPart = totalMillis % 1000;
        final long totalSeconds = totalMillis / 1000;
        final long secondsPart = totalSeconds % 60;

        final StringBuilder sb = new StringBuilder(3 + 3 + 3 + 3 + 2);
        sb.append(String.format("%02d", secondsPart));
        sb.append(".");
        sb.append(String.format("%03d", millisPart));
        sb.append(".");
        sb.append(String.format("%03d", microsPart));
        sb.append(".");
        sb.append(String.format("%03d", nanosPart));
        return sb.toString();
    }
}

Related

  1. formatTimespan(int timespan)
  2. formatTimeSpanForScheduler(long time)
  3. formatTimestamp(String timestamp)
  4. formatTimestampEnd(String timestamp)
  5. formatTimestampForFilename(final long timestamp)
  6. formatTimestampStart(String timestamp)
  7. formatTimeStep(Integer numberOfTimestepsPerYear, int stepNumber)
  8. formatTimeString(long millisecond)
  9. formatTimeString(String time)