Here you can find the source of formatSeconds(double seconds)
Parameter | Description |
---|---|
seconds | the seconds |
public static String formatSeconds(double seconds)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { /**/* w ww. j a v a 2 s. co m*/ * Formats seconds in human readable form. * * @param seconds the seconds * @return the formatted seconds */ public static String formatSeconds(double seconds) { StringBuilder result = new StringBuilder(); int minutes = (int) (seconds / 60); int digits = 1; if (seconds < 0.01) { digits = 6; } else if (seconds < 1) { digits = 3; } seconds -= minutes * 60; if (minutes > 0) { result.append(minutes).append(" m "); } result.append(String.format("%,." + digits + "f s", seconds)); return result.toString(); } }