Java Milliseconds relTimestrMillis(long time)

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

Description

rel Timestr Millis

License

Open Source License

Declaration

public static String relTimestrMillis(long time) 

Method Source Code

//package com.java2s;
/*//from   w w  w . jav  a2  s.c o  m
 * Copyright 2005-2008 by beck et al. projects GmbH, Munich
 * Copyright 2009 by Kappich Systemberatung, Aachen
 * 
 * This file is part of de.bsvrz.sys.funclib.losb.
 * 
 * de.bsvrz.sys.funclib.losb 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.
 * 
 * de.bsvrz.sys.funclib.losb 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 de.bsvrz.sys.funclib.losb.  If not, see <http://www.gnu.org/licenses/>.
    
 * Contact Information:
 * Kappich Systemberatung
 * Martin-Luther-Stra?e 14
 * 52062 Aachen, Germany
 * phone: +49 241 4090 436 
 * mail: <info@kappich.de>
 */

public class Main {
    public static String relTimestrMillis(long time) {
        long h = time / 3600000;
        long m = ((time / 1000) % 3600) / 60;
        long s = (((time / 1000) % 3600) % 60);
        long ss = time % 1000;
        return leadZero(h, 2) + "h:" + leadZero(m, 2) + "m:" + leadZero(s, 2) + "," + leadZero(ss, 3) + "s";
    }

    /**
     * Wandelt die uebergebene Zahl in einen String um und fuegt vorne Nullen an bis die angegebene Anzahl an Zeichen erreicht ist.
     *
     * @param num Zahl
     * @param anz Anzahl Zeichen
     *
     * @return Zahl mit fuehrenden Nullen als String der Laenge anz.
     */
    public static String leadZero(long num, int anz) {
        return leadZero(String.valueOf(num), anz);
    }

    /**
     * Nimmt die als String uebergebene Zahl und fuegt vorne Nullen an bis die angegebene Anzahl an Zeichen erreicht ist.
     *
     * @param num Zahl
     * @param anz Anzahl Zeichen
     *
     * @return Zahl mit fuehrenden Nullen als String der Laenge anz.
     */
    public static String leadZero(String num, int anz) {
        String erg = num;
        int le = erg.length();
        for (int i = 0; i < anz - le; i++) {
            erg = "0" + erg;
        }
        return erg;
    }
}

Related

  1. OLEDateToMillis(double dSerialDate)
  2. parseDate(long milliseconds)
  3. printTimeFromMilliseconds(long milliseconds)
  4. putMillisToByteArray(byte[] buff, long value, int offset)
  5. readableTransferRate(long size, long millis)
  6. resetHourMinSecMill(final Date date)
  7. resetMilliseconds(long msec)
  8. reverseTimeMillis(long currentTimeMillis)
  9. rollMockClockMillis(long millis)