Java BigDecimal Format formatTime(BigDecimal seconds)

Here you can find the source of formatTime(BigDecimal seconds)

Description

format Time

License

LGPL

Declaration

public static String formatTime(BigDecimal seconds) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.math.BigDecimal;

public class Main {
    private static final String TIME_FORMAT = "%02d:%02d:%02d.%03d";

    public static String formatTime(BigDecimal seconds) {
        int whole = seconds.intValue();
        BigDecimal frac = seconds.subtract(new BigDecimal(whole));

        int f = frac.multiply(new BigDecimal(1000)).intValue();

        int m = whole / 60;
        int s = whole % 60;

        int h = m / 60;
        m = m % 60;/*w ww.j  av  a2s  .  co  m*/

        return String.format(TIME_FORMAT, h, m, s, f);
    }
}

Related

  1. formatServiceSpecificDate(Date date)
  2. formatSize(Integer size)
  3. formatStore(long store)
  4. formattedFromBigDecimal(BigDecimal number, int scale, Locale locale)
  5. formattedToBigDecimal(String str, Locale locale)
  6. formatTwoDecimals(float num)
  7. formatUnwithE(Object arg)
  8. formatYuan2Fen(double fee)
  9. getFormatSizeByKB(long size)