List of utility methods to do Second Format
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; ... |
String | addSecondCa(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); |
long | calculateTimeInSeconds(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 }; |
boolean | compareDate(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; |
double | elapsedSeconds(long startTime) Get the elapsed time in seconds. return elapsedTime(startTime, System.nanoTime(), 1e9);
|
String | elapsedSeconds2(long milli) elapsed Seconds double seconds = milli / 1000.; return Double.toString(seconds); |
String | formatMiliSeconds(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;
...
|
String | formatMilliIntervalAsSeconds(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(); |
String | formatMinutesSeconds(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)); |