Java Millisecond Convert convertMillisToTicks(long milliseconds)

Here you can find the source of convertMillisToTicks(long milliseconds)

Description

Convert milliseconds to minecraft ticks (20th of a second).

License

Open Source License

Parameter

Parameter Description
milliseconds The milliseconds to convert from.

Return

The ticks converted from the millis.

Declaration

public static long convertMillisToTicks(long milliseconds) 

Method Source Code

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

public class Main {
    /**//w w  w  .jav  a2  s.c  o  m
     * Convert milliseconds to minecraft ticks (20th of a second).
     *
     * @param milliseconds The milliseconds to convert from.
     * @return The ticks converted from the millis.
     */
    public static long convertMillisToTicks(long milliseconds) {
        double nearestTickTime = round(milliseconds, 50);
        return (long) ((nearestTickTime / 1000) * 20);
    }

    /**
     * Round the value to the nearest factor.
     *
     * @param value  The value to round.
     * @param factor The factor of where to round.
     * @return The rounded value.
     */
    public static double round(double value, double factor) {
        return (Math.round(value / factor) * factor);
    }
}

Related

  1. convertMillisToHumanReadableForm(long milliseconds)
  2. convertMillisToString(long diff)
  3. convertMillisToTime(String val)
  4. convertNanosecondToMillisecondString(final long nanos)
  5. convertTimeMillisToHexString(long currentDate)
  6. convertTimeToDurationMilliseconds(String time)