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

longconvertToTenthsOfASecond(long epochSeconds, int nanos)
Event rate rate limiting uses a tenths of a seconds units to cater to monitor intervals of 0.1 seconds, 0.5 seconds etc..
int tenthsPieceOfNanos = (nanos / (100000000));
if (tenthsPieceOfNanos > 9) {
    throw new NumberFormatException(
            "Tenths of nanos cannot be greater than 9 but this is " + tenthsPieceOfNanos);
return epochSeconds * 10 + tenthsPieceOfNanos;
StringsecondConvertToString(final long spentSeconds)
Convert the seconds to jira format (1h 30m) String.
String summaryString = "";
long spentMin = spentSeconds / SECONDS_PER_MINUTE;
long spentHour = spentMin / MINUTES_PER_HOUR;
long days = spentHour / WORK_HOURS_PER_DAY;
long hours = spentHour % WORK_HOURS_PER_DAY;
long mins = spentMin % MINUTES_PER_HOUR;
if (days != 0) {
    summaryString = days + "d " + hours + "h " + mins + "m";
...
doubleseconds2microseconds(double secs)
Convert its argument from seconds to microseconds.
return 1000000d * secs;
Stringseconds2String(long seconds)
seconds String
int minutes = (int) seconds / 60;
seconds = seconds % 60;
return minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
Stringseconds2time(long seconds)
Converts a value in seconds to: "d:hh:mm:ss" where d=days, hh=hours, mm=minutes, ss=seconds, or "h:mm:ss" where h=hours<24, mm=minutes, ss=seconds, or "m:ss" where m=minutes<60, ss=seconds
long minutes = seconds / 60;
seconds = seconds - minutes * 60;
long hours = minutes / 60;
minutes = minutes - hours * 60;
long days = hours / 24;
hours = hours - days * 24;
StringBuilder time = new StringBuilder();
if (days != 0) {
...
intseconds2timecents(double seconds)
secondstimecents
if (seconds <= 0) {
    return -32768;
} else if (seconds >= 165910888) {
    return 32767;
return (int) (1200.0 * Math.log(seconds) / Math.log(2));
longsecondsToCycles(double secs, double hz)
seconds To Cycles
return (long) (hz * secs);
StringsecondsToHHMMSS(int secs)
seconds To HHMMSS
String result = "";
int hours = secs / 3600, remainder = secs % 3600, minutes = remainder / 60, seconds = remainder % 60;
String disHour = (hours < 10 ? "0" : "") + hours, disMinu = (minutes < 10 ? "0" : "") + minutes,
        disSec = (seconds < 10 ? "0" : "") + seconds;
result = disHour + ":" + disMinu + ":" + disSec;
return result;
StringsecondsToHHMMSS(long secs)
seconds To HHMMSS
int hours = (int) (secs / 3600);
int remainder = (int) (secs % 3600);
int minutes = remainder / 60;
int seconds = remainder % 60;
return ((hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes + ":"
        + (seconds < 10 ? "0" : "") + seconds);
StringsecondsToHour(int time)
seconds To Hour
if (time < 0)
    return null;
int hours = (time / 3600) % 12;
String hoursStr = hours == 0 ? "12" : hours + "";
return hoursStr;