Java Time Format formatTime(long time)

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

Description

Formatea el tiempo en milisegundos devolviendo un String en formato .

License

Open Source License

Parameter

Parameter Description
time Tiempo en milisegundos

Declaration

public static String formatTime(long time) 

Method Source Code

//package com.java2s;
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
 *
 * Copyright (C) 2008 IVER T.I. and Generalitat Valenciana.
 *
 * This program 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 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 *//*  w  w  w.  java 2 s. com*/

public class Main {
    /**
     * Formatea el tiempo en milisegundos devolviendo un String en formato . dias,
     * horas, minutos y segundos.
     * @param time Tiempo en milisegundos
     */
    public static String formatTime(long time) {
        int days = 0;
        int hours = 0;
        int minuts = 0;
        int seconds = (int) (time / 1000D);
        if (seconds >= 60) {
            minuts = (seconds / 60);
            seconds = (seconds - (minuts * 60));
            if (minuts >= 60) {
                hours = (minuts / 60);
                minuts = (minuts - (hours * 60));
                if (hours >= 24) {
                    days = (hours / 24);
                    hours = (hours - (days * 24));
                }
            }
        }
        StringBuffer s = new StringBuffer();
        if (days != 0)
            s.append(days + " d ");
        if (hours != 0)
            s.append(hours + " h ");
        if (minuts != 0)
            s.append(minuts + " min ");
        if (seconds != 0)
            s.append(seconds + " s ");
        if (s.length() == 0)
            s.append(" < 1s");
        return s.toString();
    }
}

Related

  1. formatTime(Long num)
  2. formatTime(long sec)
  3. formatTime(long seconds)
  4. formatTime(long seconds)
  5. formatTime(long seconds)
  6. formatTime(long time)
  7. formatTime(long time)
  8. formatTime(long time)
  9. formatTime(long time)