Java Utililty Methods Second Convert

List of utility methods to do Second Convert

Description

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

Method

StringsecondsToStringWithUnits(double value)
seconds To String With Units
String result = value > 0 ? "" : "0 secs";
double secondsRemaining = value;
if (secondsRemaining > WEEK) {
    long numUnits = (long) (secondsRemaining / WEEK);
    secondsRemaining = secondsRemaining % WEEK;
    result += numUnits;
    result += numUnits > 1 ? " wks " : " wk ";
if (secondsRemaining > DAY) {
    long numUnits = (long) (secondsRemaining / DAY);
    secondsRemaining = secondsRemaining % DAY;
    result += numUnits;
    result += numUnits > 1 ? " days " : " day ";
if (secondsRemaining > HOUR) {
    long numUnits = (long) (secondsRemaining / HOUR);
    secondsRemaining = secondsRemaining % HOUR;
    result += numUnits;
    result += numUnits > 1 ? " hrs " : " hr ";
if (secondsRemaining > MINUTE) {
    long numUnits = (long) (secondsRemaining / MINUTE);
    secondsRemaining = secondsRemaining % MINUTE;
    result += numUnits;
    result += numUnits > 1 ? " mins " : " min ";
if (secondsRemaining > 0) {
    result += (long) secondsRemaining;
    result += secondsRemaining > 1 ? " secs" : " sec";
return result;
longsecondsToTicks(double seconds)
Returns the number of ticks a timer torch (and perhaps delay torch) should wait before reverting.
double t = seconds * 20; 
return Math.round(t);
intsecondsToTicks(double x)
standard MC ratio
return (int) x * TICKS_PER_SEC;
intsecondsToTicks(float seconds)
seconds To Ticks
return (int) seconds * 20;
intsecondsToTicks(int seconds)
seconds To Ticks
return seconds * 20;
StringsecondsToTime(double seconds)
seconds To Time
int hours = (int) (seconds / 3600);
int minutes = (int) ((seconds % 3600) / 60);
int secs = (int) (seconds % 60);
return String.format("%02d:%02d:%02d", hours, minutes, secs);
StringsecondsToTime(int seconds)
Parses the seconds and returns time in HOUR:MIN:SEC format
int hour = (int) Math.floor(seconds / 3600);
int min = (int) Math.floor((seconds - (hour * 3600)) / 60);
int sec = seconds - (hour * 3600) - (min * 60);
String resetTime = min + ":";
if (min < 10)
    resetTime = "0" + resetTime;
resetTime = hour + ":" + resetTime;
if (sec < 10)
...
StringsecondsToTime(int seconds)
seconds To Time
if (seconds == 0) {
    return "0 sekund";
int minutes = seconds / 60;
seconds %= 60;
int hours = minutes / 60;
minutes %= 60;
int days = hours / 24;
...
StringsecondsToTime(long timeseconds)
seconds To Time
StringBuilder builder = new StringBuilder();
int years = (int) (timeseconds / (60 * 60 * 24 * 365));
if (years > 0) {
    builder.append("**").append(years).append("** years, ");
    timeseconds = timeseconds % (60 * 60 * 24 * 365);
int weeks = (int) (timeseconds / (60 * 60 * 24 * 365));
if (weeks > 0) {
...
StringsecondsToTimeClock(int totalSeconds)
seconds To Time Clock
double totalSecondsDouble = (int) totalSeconds;
int minutes = (int) (Math.floor(totalSecondsDouble / 60));
int seconds = (int) (totalSecondsDouble % 60);
return "" + (minutes > 0 ? minutes : "0") + ":"
        + (seconds < 1 ? "00" : (seconds < 10 ? "0" : "") + seconds);