Android Long to Date Convert getTimeInterval(long interval)

Here you can find the source of getTimeInterval(long interval)

Description

get Time Interval

Parameter

Parameter Description
startDate Interval start date time
endDate Interval end date time

Return

Time interval in format hh:mm:ss

Declaration


public static String getTimeInterval(long interval) 

Method Source Code

//package com.java2s;

public class Main {
    /** /*  w ww  .ja v  a  2  s . c  o m*/
     * 
     * @param startDate Interval start date time
     * @param endDate Interval end date time
     * @return Time interval in format hh:mm:ss
     */

    public static String getTimeInterval(long interval) {
        if (interval <= 0) {
            return "00:00:00";
        }
        long intervalSeconds = interval / 1000;
        long hours = intervalSeconds / 3600;
        long minutes = (intervalSeconds % 3600) / 60;
        long seconds = intervalSeconds % 60;
        String hoursText = String.valueOf(hours);
        if (hoursText.length() == 1) {
            hoursText = "0" + hoursText;
        }
        String minutesText = String.valueOf(minutes);
        if (minutesText.length() == 1) {
            minutesText = "0" + minutesText;
        }
        String secondsText = String.valueOf(seconds);
        if (secondsText.length() == 1) {
            secondsText = "0" + secondsText;
        }
        return hoursText + ":" + minutesText + ":" + secondsText;
    }
}

Related

  1. getShortDateTimeString(long date, Locale locale)
  2. getSimpleDatetime(long milliseconds)
  3. getStandardTime(long timestamp)
  4. getStartTimeOfDay(long timeInLong)
  5. getStringOfLong(long date)
  6. getTimeLabel(long date)
  7. getTimeLabel(long time)
  8. getTimestampDatetime(long milliseconds)
  9. getUTCTimeFromElapsedTime(long elapsedTime)