Java Time Format formatTime(final long time)

Here you can find the source of formatTime(final long time)

Description

Formats time from long to a readable String

License

Open Source License

Parameter

Parameter Description
time Raw time input

Return

Readable time

Declaration

public static String formatTime(final long time) 

Method Source Code

//package com.java2s;
/*/*from ww w  .jav a2 s .c  o  m*/
 * This file is part of SpaceBukkit (http://spacebukkit.xereo.net/).
 *
 * SpaceBukkit is free software: you can redistribute it and/or modify it under the terms of the
 * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license as published by the Creative
 * Common organization, either version 3.0 of the license, or (at your option) any later version.
 *
 * SpaceBukkit 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
 * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license for more details.
 *
 * You should have received a copy of the Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA)
 * license along with this program. If not, see <http://creativecommons.org/licenses/by-nc-sa/3.0/>.
 */

public class Main {
    /**
     * Formats time from long to a readable String
     * @param time Raw time input
     * @return Readable time
     */
    public static String formatTime(final long time) {
        final int hours = (int) ((time / 1000 + 8) % 24);
        final int minutes = (int) (60 * (time % 1000) / 1000);
        return String.format("%02d:%02d (%d:%02d %s)", hours, minutes, hours % 12 == 0 ? 12 : hours % 12, minutes,
                hours < 12 ? "am" : "pm");
    }
}

Related

  1. formattedUnixTime()
  2. formatTime(byte[] btValue, int iOffset, int iLength)
  3. formatTime(double time)
  4. formatTime(double totalTime)
  5. formatTime(final int timeSec)
  6. formatTime(final long time)
  7. formatTime(final long timeMS)
  8. formatTime(float seconds)
  9. formatTime(int minutes)