Java Utililty Methods Second Format

List of utility methods to do Second Format

Description

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

Method

Float_toSeconds(String strTime)
to Seconds
Float time = 0F;
try {
    if (strTime.endsWith("s")) {
        time = Float.parseFloat(strTime.replace("s", "")) * 1;
    } else if (strTime.endsWith("m")) {
        time = Float.parseFloat(strTime.replace("m", "")) * 60;
    } else if (strTime.endsWith("h")) {
        time = Float.parseFloat(strTime.replace("h", "")) * 60 * 60;
...
StringaddSecondCa(String d1, int timeSpan, String format)
add Second Ca
Date d1Date = toDate(d1, format);
long timeMili = d1Date.getTime() + timeSpan * 1000;
d1Date.setTime(timeMili);
return formatDateString(d1Date, format);
longcalculateTimeInSeconds(long startTimeInMilliseconds, long endTimeInMilliseconds)
calculate Time In Seconds
long timeInSeconds = endTimeInMilliseconds - startTimeInMilliseconds;
float time = (float) timeInSeconds;
float result = time / 1000;
return (long) result;
long[]changeSecondsToTime(long seconds)
change Seconds To Time
long hour = seconds / 3600;
long minute = (seconds - hour * 3600) / 60;
long second = (seconds - hour * 3600 - minute * 60);
return new long[] { hour, minute, second };
booleancompareDate(String fistDate, String secondDate, String format)
compare Date
boolean flag = false;
Date fist = null;
Date second = null;
fist = getDateFromString(fistDate, format);
second = getDateFromString(secondDate, format);
if (fist.before(second)) {
    flag = true;
return flag;
doubleelapsedSeconds(long startTime)
Get the elapsed time in seconds.
return elapsedTime(startTime, System.nanoTime(), 1e9);
StringelapsedSeconds2(long milli)
elapsed Seconds
double seconds = milli / 1000.;
return Double.toString(seconds);
StringformatMiliSeconds(long time)
Format time interval for humans
long hours, minutes, seconds, mseconds;
mseconds = time % 1000;
time = time / 1000;
hours = time / 3600;
time = time - (hours * 3600);
minutes = time / 60;
time = time - (minutes * 60);
seconds = time;
...
StringformatMilliIntervalAsSeconds(long interval)
Format a millisecond interval as number of seconds (with fracitonal part).
long seconds = interval / 1000;
long millis = interval - seconds * 1000;
StringBuilder buff = new StringBuilder();
buff.append(seconds).append(".");
buff.append(millis).append("s");
return buff.toString();
StringformatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit)
Formats the specified duration in 'mm:ss.SSS' format.
final long millis = TimeUnit.MILLISECONDS.convert(sourceDuration, sourceUnit);
final SimpleDateFormat formatter = new SimpleDateFormat("mm:ss.SSS", Locale.US);
return formatter.format(new Date(millis));