Here you can find the source of formatDuration(long durationSec)
Parameter | Description |
---|---|
durationSec | Duration in seconds |
public static String formatDuration(long durationSec)
//package com.java2s; /* ------------------------------------------------------------------------- OpenTripPlanner GWT Client/*ww w . j a v a 2s .c o m*/ Copyright (C) 2015 Mecatran - info@mecatran.com This program 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 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ------------------------------------------------------------------------- */ public class Main { /** * @param durationSec * Duration in seconds * @return Duration nicely formatted (eg: 37mn, 1h38) */ public static String formatDuration(long durationSec) { long min = (durationSec + 30L) / 60L; long hour = min / 60L; min %= 60L; if (hour == 0L) { return min + smallerFont("mn"); } else { return hour + smallerFont("h") + (min < 10 ? "0" : "") + min; } } /** * Make a font smaller (css font class 'smaller'). * * @param html * @return */ public static String smallerFont(String html) { return "<span class='smaller'>" + html + "</span>"; } }