Java Time Readable Format toTimeString(long frame)

Here you can find the source of toTimeString(long frame)

Description

to Time String

License

Apache License

Declaration

public static String toTimeString(long frame) 

Method Source Code

//package com.java2s;
/*/*w w w.j  a  v a  2  s.  c o  m*/
 * Copyright (C) 2011 aki@akjava.com
 *
 * 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 {
    public static String toTimeString(long frame) {
        long hour = (long) (frame / (60 * 60 * 1000));
        long remain = (long) (frame % (60 * 60 * 1000));

        long minute = remain / (60 * 1000);
        remain = remain % (60 * 1000);

        long second = remain / 1000;
        remain = remain % 1000;

        String result = "";
        if (hour < 10) {
            result = "0" + hour;
        } else {
            result += hour;
        }
        result += ":";
        if (minute < 10) {
            result += "0" + minute;
        } else {
            result += minute;
        }
        result += ":";
        if (second < 10) {
            result += "0" + second;
        } else {
            result += second;
        }
        long milli = remain * 60 / 1000;
        if (milli < 10) {
            result += ":" + "0" + milli;
        }

        else {
            result += ":" + milli;
        }

        return result;

    }
}

Related

  1. toTimeHumanReadable(final long time)
  2. toTimeSpanDescription(long time)
  3. toTimestamp(long time)
  4. toTimeStampString(String timeStr)
  5. toTimeString(double millis)
  6. toTimeString(long millis)
  7. toTimeString(long millis, boolean showSeconds, String separatorHours, String separatorMin, String separatorSec)
  8. toTimeString(long seconds)
  9. toTimeStringForceShowHours(long millis, boolean showSeconds, boolean showUnits)