Java TimeUnit Usage calculateTime(float seconds)

Here you can find the source of calculateTime(float seconds)

Description

Returns a string representation of elapsed time from seconds to days:hr:min:s

License

Open Source License

Parameter

Parameter Description
seconds The number of seconds

Declaration

public static String calculateTime(float seconds) 

Method Source Code

//package com.java2s;
/**//  w  ww.  j  a  va  2s  .c  om
 * Candybean is a next generation automation and testing framework suite.
 * It is a collection of components that foster test automation, execution
 * configuration, data abstraction, results illustration, tag-based execution,
 * top-down and bottom-up batches, mobile variants, test translation across
 * languages, plain-language testing, and web service testing.
 * Copyright (C) 2013 SugarCRM, Inc. <candybean@sugarcrm.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.concurrent.TimeUnit;

public class Main {
    /**
     * Returns a string representation of elapsed time from seconds to days:hr:min:s
     * @param seconds The number of seconds
     * @return
     */
    public static String calculateTime(float seconds) {
        double partialSeconds = (double) (seconds - ((int) seconds));
        int milliseconds = (int) (partialSeconds * 1000);
        long secs = (long) seconds;
        int day = (int) TimeUnit.SECONDS.toDays(secs);
        long hours = TimeUnit.SECONDS.toHours(secs) - (day * 24);
        long minute = TimeUnit.SECONDS.toMinutes(secs) - (TimeUnit.SECONDS.toHours(secs) * 60);
        long second = TimeUnit.SECONDS.toSeconds(secs) - (TimeUnit.SECONDS.toMinutes(secs) * 60);
        return day + "days " + hours + "hr " + minute + "min " + second + "s " + milliseconds + "ms";
    }
}

Related

  1. age(long creationDate)
  2. areEqualTTL(final Integer ttlDuration1, final Integer ttlDuration2)
  3. calculateDaysBetween(final Calendar start, final Calendar end)
  4. calculateRuntime(long startTime, long endTime)
  5. calculateTime(final int seconds)
  6. cancelledFuture()
  7. convertMilisecondsToDetail(long ms)
  8. convertMillis(long millis)
  9. convertMillisecondsToHHMMSS(long milliseconds)