Java Minute Convert convertTicksToMinutesAndSeconds(int ticks, boolean fraction)

Here you can find the source of convertTicksToMinutesAndSeconds(int ticks, boolean fraction)

Description

Takes in the amount of ticks, and converts it into a time notation.

License

Open Source License

Parameter

Parameter Description
ticks a parameter
fraction When true, 30 ticks will show as '1.5s' instead of '1s'.

Declaration

public static String convertTicksToMinutesAndSeconds(int ticks,
        boolean fraction) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

public class Main {
    /**/*w w  w . j a v a2  s.  c om*/
     * Takes in the amount of ticks, and converts it into a time notation. 40 ticks will become "2s", while 2400 will result in "2m".
     * @param ticks
     * @param fraction When true, 30 ticks will show as '1.5s' instead of '1s'.
     * @return
     */
    public static String convertTicksToMinutesAndSeconds(int ticks,
            boolean fraction) {
        String part = ticks % 20 * 5 + "";
        if (part.length() < 2)
            part = "0" + part;
        ticks /= 20;// first convert to seconds.
        if (ticks < 60) {
            return ticks + (fraction ? "." + part : "") + "s";
        } else {
            return ticks / 60 + "m";
        }
    }
}

Related

  1. convertMsToMinutesAndSeconds(long ms)
  2. convertOffsetToMinutesSeconds(int offset)
  3. convertOffsetToMinutesSecondsMillis(int offset)
  4. convertSecondsToHoursMinutesSeconds(int offset)
  5. convertSecondsToMinutes(double seconds)
  6. convertTimemilisecondsToMinutes(long time)
  7. minutesToHHMM(int mins)
  8. minutesToMillis(double minutes)
  9. minutesToMillis(int minutes)