Here you can find the source of secondstoHM(long sec)
public static String secondstoHM(long sec)
//package com.java2s; /*/* w w w .j a v a2 s.c om*/ * This file is part of Java Tools for hdsdi3g'. * * 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 3 of the License, or * 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. * * Copyright (C) hdsdi3g for hd3g.tv 2009-2012 * */ public class Main { /** * Converti une valeur en secondes sous la forme HH:MM */ public static String secondstoHM(long sec) { StringBuffer sb = new StringBuffer(); int hrs = getHoursInSec(sec); if (hrs < 10) { sb.append(0); } sb.append(hrs); sb.append(":"); //$NON-NLS-1$ int min = Math.round(getMinutesInSecWOHours(sec)); if (min < 10) { sb.append(0); } sb.append(min); return sb.toString(); } /** * @param sec les secondes a calculer. * @return le nombre d'heures que contient sec. * @see getMinutesInSecWOHours. */ public static int getHoursInSec(long sec) { return (int) Math.floor((float) sec / 3600f); // en heures } /** * @param sec les secondes a calculer. * @return le nombre de minutes que contient sec sans les heures. * @see getHoursInSec. */ public static float getMinutesInSecWOHours(long sec) { float _diff_hours = (float) sec / 3600f; // en heures,minutes int diff_hours = (int) Math.floor(_diff_hours); // en heures return ((float) _diff_hours - (float) diff_hours) * 60f; } }