Java DateTimeFormatter formatTime(long milliSeconds)

Here you can find the source of formatTime(long milliSeconds)

Description

Formats a timestamp in a format suitable to be presented to the user using the current timezone.

License

Open Source License

Parameter

Parameter Description
milliSeconds milliseconds since the Unix Epoch.

Return

formatted time.

Declaration

public static String formatTime(long milliSeconds) 

Method Source Code

//package com.java2s;
/*/*from  www . j av  a 2s.c  o  m*/
 * Copyright (c) 2004-2016 Universidade do Porto - Faculdade de Engenharia
 * Laborat?rio de Sistemas e Tecnologia Subaqu?tica (LSTS)
 * All rights reserved.
 * Rua Dr. Roberto Frias s/n, sala I203, 4200-465 Porto, Portugal
 *
 * This file is part of Neptus, Command and Control Framework.
 *
 * Commercial Licence Usage
 * Licencees holding valid commercial Neptus licences may use this file
 * in accordance with the commercial licence agreement provided with the
 * Software or, alternatively, in accordance with the terms contained in a
 * written agreement between you and Universidade do Porto. For licensing
 * terms, conditions, and further information contact lsts@fe.up.pt.
 *
 * European Union Public Licence - EUPL v.1.1 Usage
 * Alternatively, this file may be used under the terms of the EUPL,
 * Version 1.1 only (the "Licence"), appearing in the file LICENCE.md
 * included in the packaging of this file. You may not use this work
 * except in compliance with the Licence. Unless required by applicable
 * law or agreed to in writing, software distributed under the Licence is
 * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the Licence for the specific
 * language governing permissions and limitations at
 * http://ec.europa.eu/idabc/eupl.html.
 *
 * For more information please see <http://lsts.fe.up.pt/neptus>.
 *
 * Author: Paulo Dias
 * 2008/04/16
 */

import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class Main {
    /** Default time format. */
    private static final DateTimeFormatter defaultTimeFormat = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
    /** Currently configured timezone. */
    private static final ZoneId currentZoneId = ZoneId.of("UTC");

    /**
     * Formats a timestamp in a format suitable to be presented to the user using the current timezone.
     *
     * @param milliSeconds milliseconds since the Unix Epoch.
     * @return formatted time.
     */
    public static String formatTime(long milliSeconds) {
        return formatTime(milliSeconds, currentZoneId);
    }

    /**
     * Formats a timestamp in a format suitable to be presented to the user using a given timezone.
     *
     * @param milliSeconds milliseconds since the Unix Epoch.
     * @param zoneId timezone identifier.
     * @return formatted time.
     */
    public static String formatTime(long milliSeconds, ZoneId zoneId) {
        return Instant.ofEpochMilli(milliSeconds).atZone(zoneId).format(defaultTimeFormat);
    }
}

Related

  1. formatDateAndTime(String dateAndTime)
  2. formatDateTime(Date dateTime)
  3. formatDateTime(long milis)
  4. formatISOUTCDateTime(long timestamp)
  5. formatNow(String format)
  6. formatTimestamp(long timestamp)
  7. formatTimestap(final long timestap)
  8. fromInfluxDBTimeFormat(final String timestamp)
  9. fromString(String dateString, DateTimeFormatter formatter)