Android Long to Date Convert millisToShortDHMS(long duration)

Here you can find the source of millisToShortDHMS(long duration)

Description

converts time (in milliseconds) to human-readable format "hh:mm:ss"

License

Open Source License

Declaration

public static String millisToShortDHMS(long duration) 

Method Source Code

//package com.java2s;
/*/*from  ww  w .j a  va 2s  .  co m*/
 *  This file is part of SWADroid.
 *
 *  Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com>
 *
 *  SWADroid is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  SWADroid 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
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with SWADroid.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Locale;

public class Main {
    public final static long ONE_SECOND = 1000;
    public final static long SECONDS = 60;
    public final static long MINUTES = 60;
    public final static long HOURS = 24;

    /**
     * converts time (in milliseconds) to human-readable format
     * "<dd:>hh:mm:ss"
     */
    public static String millisToShortDHMS(long duration) {
        String res = "";
        duration /= ONE_SECOND;
        int seconds = (int) (duration % SECONDS);
        duration /= SECONDS;
        int minutes = (int) (duration % MINUTES);
        duration /= MINUTES;
        int hours = (int) (duration % HOURS);
        int days = (int) (duration / HOURS);
        if (days == 0) {
            res = String.format(Locale.getDefault(), "%02d:%02d:%02d",
                    hours, minutes, seconds);
        } else {
            res = String.format(Locale.getDefault(), "%dd%02d:%02d:%02d",
                    days, hours, minutes, seconds);
        }
        return res;
    }
}

Related

  1. longTimeToDate(long miliseconds)
  2. longTimeToString(int i)
  3. longToCalendar(Long time)
  4. longToSqlDateFormat(long date)
  5. millisToLongDHMS(long duration)
  6. nextDate(long timeMilliSeconds)
  7. parseMills2Time(long elapsedMills)
  8. shortFromUtc(long milliseconds)
  9. timeInMillisToText(final long totalTimeInMillis)