Here you can find the source of formatSeconds(long secsIn)
Parameter | Description |
---|---|
secsIn | the number of seconds |
public static String formatSeconds(long secsIn)
//package com.java2s; /******************************************************************************* * Gisgraphy Project //from w ww .j a v a 2s . co m * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA * * Copyright 2008 Gisgraphy project * David Masclet <davidmasclet@gisgraphy.com> * * *******************************************************************************/ public class Main { /** * @param secsIn * the number of seconds * @return a human reading strings. example :1 hour 6 minuts 40 seconds. */ public static String formatSeconds(long secsIn) { long hours = secsIn / 3600, remainder = secsIn % 3600, minutes = remainder / 60, seconds = remainder % 60; String displayhours = hours == 0 ? "" : hours + " hour" + getPlural(hours); String displayMin = minutes == 0 ? "" : minutes + " minut" + getPlural(minutes); String displaySec = seconds == 0 ? "" : seconds + " second" + getPlural(seconds); return displayhours + displayMin + displaySec; } private static String getPlural(long count) { return count > 1 ? "s " : " "; } }