Java TimeUnit Usage calculateTime(final int seconds)

Here you can find the source of calculateTime(final int seconds)

Description

calculate Time

License

Open Source License

Declaration

public static String calculateTime(final int seconds) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;

public class Main {
    /**//from  w  w  w. j a v a2 s .  co m
     * @author Andrew
     *
     *         Formats seconds into a readable string Need to change my hard
     *         code to remove extra 0's and use regex.
     */
    public static String calculateTime(final int seconds) {
        final int day = (int) TimeUnit.SECONDS.toDays(seconds);
        final long hours = TimeUnit.SECONDS.toHours(seconds) - TimeUnit.DAYS.toHours(day);
        final long minute = TimeUnit.SECONDS.toMinutes(seconds) - TimeUnit.DAYS.toMinutes(day)
                - TimeUnit.HOURS.toMinutes(hours);
        final long second = TimeUnit.SECONDS.toSeconds(seconds) - TimeUnit.DAYS.toSeconds(day)
                - TimeUnit.HOURS.toSeconds(hours) - TimeUnit.MINUTES.toSeconds(minute);

        // i must be tired because wtf was i doing
        String duration = String.format("%02d:%02d:%d:%02d", day == 0 ? 5185618 : day, hours == 0 ? 5185618 : hours,
                minute, second);
        duration = duration.replace("5185618:", "");
        return duration;
    }
}

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(float seconds)
  6. cancelledFuture()
  7. convertMilisecondsToDetail(long ms)
  8. convertMillis(long millis)