Java Millisecond Convert millisToSeconds(long millis)

Here you can find the source of millisToSeconds(long millis)

Description

Converts time in milliseconds to a String representing the time in seconds in the format XX.XXX

License

Apache License

Parameter

Parameter Description
millis the time in milliseconds that we want to convert

Return

a String representing the time in seconds in the format XX.XXX

Declaration

public static String millisToSeconds(long millis) 

Method Source Code

//package com.java2s;
/*/*from w w w  .  j a  v  a2 s. c o  m*/
/*
 * Jipopro, the Jitsi Post-Processing application for recorded conferences.
 *
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /** Converts time in milliseconds to a String representing the time in
     * seconds in the format XX.XXX
     * @param millis the time in milliseconds that we want to convert
     * @return a String representing the time in seconds in the format XX.XXX
     */
    public static String millisToSeconds(long millis) {
        String result = "";
        String complement = "";
        long fraction = Math.abs(millis) % 1000;

        if (fraction < 10) {
            complement = "00";
        } else if (fraction < 100) {
            complement = "0";
        }

        result += millis / 1000;
        result += ".";
        result += complement + fraction;

        return result;
    }
}

Related

  1. millisToNanos(int i)
  2. millisToNanos(long millis)
  3. millisToNanos(long millis)
  4. millisToSecond(long millisecond)
  5. millisToSeconds(final long millis)
  6. millisToSeconds(long millis)
  7. millisToSeconds(long millis)
  8. millisToShortDHMS(long duration)
  9. millisToString(float millis)