Here you can find the source of durationToString(Long ms)
static public String durationToString(Long ms)
//package com.java2s; /*//from w w w .j av a2s . co m * Copyright * 2009 axYus - www.axyus.com * 2009 C.Bosquet - charles.bosquet@axyus.com * * This file is part of XEMELIOS. * * XEMELIOS 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 of the License, or * (at your option) any later version. * * XEMELIOS 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 XEMELIOS; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ public class Main { static public String durationToString(Long ms) { if (ms == null) { return null; } StringBuffer sb = new StringBuffer(); // on aura pas de traitement qui dure plus d'un an ! // if (ms >= 31536000000l) { // long years = ms / 31536000000l; // ms = ms % 31536000000l; // sb.append(years); // sb.append(" An" + (years > 1 ? "s " : "")); // } // if (ms >= 86400000l) { long days = ms / 86400000l; ms = ms % 86400000l; // sb.append(sb.length() > 0 ? " " : ""); if (days < 10) sb.append("0"); sb.append(days); sb.append("j "); // sb.append(" Jour" + (days > 1 ? "s " : "")); // } // if (ms >= 3600000l) { long hours = ms / 3600000l; ms = ms % 3600000l; // sb.append(sb.length() > 0 ? " " : ""); if (hours < 10) sb.append("0"); sb.append(hours); sb.append(":"); // sb.append(" Heure" + (hours > 1 ? "s " : "")); // } // if (ms >= 60000l) { long minutes = ms / 60000l; ms = ms % 60000l; // sb.append(sb.length() > 0 ? " " : ""); if (minutes < 10) sb.append("0"); sb.append(minutes); // sb.append(" Minute" + (minutes > 1 ? "s " : "")); sb.append(":"); // } // if (ms >= 1000l) { long secondes = ms / 1000l; ms = ms % 1000l; // sb.append(sb.length() > 0 ? " " : ""); if (secondes < 10) sb.append("0"); sb.append(secondes); // sb.append(" Seconde" + (secondes > 1 ? "s" : "")); sb.append("."); // } // if ((ms > 0l) || (sb.length() < 1)) { // sb.append(sb.length() > 0 ? " " : ""); if (ms < 100) sb.append("0"); if (ms < 10) sb.append("0"); sb.append(ms); // + " ms" // } return sb.toString(); } }