Here you can find the source of formatTimePeriod(long timePeriod)
Parameter | Description |
---|---|
timePeriod | time period to format |
public static final String formatTimePeriod(long timePeriod)
//package com.java2s; /*// w w w . ja v a 2s .c o m Copyright 2009 Semantic Discovery, Inc. (www.semanticdiscovery.com) This file is part of the Semantic Discovery Toolkit. The Semantic Discovery Toolkit 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 3 of the License, or (at your option) any later version. The Semantic Discovery Toolkit 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 The Semantic Discovery Toolkit. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Formats a time period in legible terms - not a date represented as a long, * but a period of time (eg processing time) * @param timePeriod time period to format */ public static final String formatTimePeriod(long timePeriod) { int hours = (int) timePeriod / 3600000; timePeriod = timePeriod % 3600000; int minutes = (int) timePeriod / 60000; timePeriod = timePeriod % 60000; int seconds = (int) timePeriod / 1000; timePeriod = timePeriod % 1000; return (hours > 0 ? hours + "h " : "") + (minutes > 0 ? minutes + "m " : "") + (seconds > 0 ? seconds + "s " : "") + (timePeriod > 0 ? timePeriod + "ms " : ""); } }