Here you can find the source of formatTime(long time)
Parameter | Description |
---|---|
time | a parameter |
public static String formatTime(long time)
//package com.java2s; /*/*from ww w. j av a 2 s. c om*/ * ? Copyright IBM Corp. 2009,2011 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ public class Main { private static final long SECOND = 1000L; private static final long MINUTE = 60 * SECOND; private static final long HOUR = 60 * MINUTE; private static final long DAY = 24 * HOUR; /** * @param time * @return */ public static String formatTime(long time) { if (time < MINUTE) { return (time / SECOND + " seconds"); // $NON-NLS-1$ } else if (time < HOUR) { long mn = time / MINUTE; return (mn + " minute(s) " + formatTime(time - (mn * MINUTE))); // $NON-NLS-1$ } else if (time < DAY) { long hours = time / HOUR; return (hours + " hour(s) " + formatTime(time - (hours * HOUR))); // $NON-NLS-1$ } else { long days = time / DAY; return (days + " day(s) " + formatTime(time - (days * DAY))); // $NON-NLS-1$ } } }