Java Utililty Methods Millisecond Convert

List of utility methods to do Millisecond Convert

Description

The list of methods to do Millisecond Convert are organized into topic(s).

Method

StringconvertMillisToHumanReadableForm(long milliseconds)
convert Millis To Human Readable Form
if (milliseconds < 0) {
    return "CANNOT_CONVERT";
if (milliseconds > 86400000) {
    return getNumberOfDays(milliseconds);
} else {
    return getNumberOfHours(milliseconds);
StringconvertMillisToString(long diff)
convert Millis To String
if (diff == 0)
    return "";
try {
    long number = 0;
    String unit = "";
    if (diff / MILLIS_PER_YEAR > 0) {
        number = diff / MILLIS_PER_YEAR;
        unit = "year";
...
longconvertMillisToTicks(long milliseconds)
Convert milliseconds to minecraft ticks (20th of a second).
double nearestTickTime = round(milliseconds, 50);
return (long) ((nearestTickTime / 1000) * 20);
StringconvertMillisToTime(String val)
Convert millis to time.
long milliseconds = Long.parseLong(val);
long seconds, minutes, hours;
seconds = milliseconds / 1000;
minutes = seconds / 60;
seconds = seconds % 60;
hours = minutes / 60;
minutes = minutes % 60;
if (hours > 0) {
...
StringconvertNanosecondToMillisecondString(final long nanos)
This method creates a microsecond string or, if zero microseconds, a two digit decimal representation.
final String longString = Long.toString(nanos);
final long ms = nanos / 1000000;
if (0 == ms) {
    if (longString.length() == 6) {
        return "." + longString.substring(0, 3);
    } else if (longString.length() == 5) {
        return ".0" + longString.substring(0, 2);
    } else if (longString.length() == 4) {
...
StringconvertTimeMillisToHexString(long currentDate)
convert Time Millis To Hex String
return String.format("%012x", currentDate);
longconvertTimeToDurationMilliseconds(String time)
Convert a time string in format HH:MM:SS in a milliseconds duration.
long retObj = 0;
if (time != null) {
    try {
        Integer hours = Integer.valueOf(time.substring(0, 2));
        Integer minutes = Integer.valueOf(time.substring(3, 5));
        Integer seconds = Integer.valueOf(time.substring(6, 8));
        retObj += hours * 60 * 60 * 1000;
        retObj += minutes * 60 * 1000;
...
intconvertToMillis(float timeInSeconds)
convert To Millis
return (int) (timeInSeconds * 1000f);
intconvertToMillis(String time)
convert To Millis
int millis = 100;
try {
    millis = Integer.parseInt(time);
} catch (NumberFormatException nfe) {
    System.out.println("" + nfe.getMessage());
    nfe.printStackTrace();
return millis;
...
longconvertToMilliseconds(String value)
convert To Milliseconds
long multiplier = 1;
if (value.endsWith("ms")) {
    value = value.substring(0, value.length() - 2).trim();
} else if (value.endsWith("min")) {
    value = value.substring(0, value.length() - 3).trim();
    multiplier = 60 * 1000;
} else if (value.endsWith("mins")) {
    value = value.substring(0, value.length() - 4).trim();
...