List of utility methods to do Second
long | currentSecondsPlus(final long seconds) current Seconds Plus return currentSeconds() + seconds;
|
int[] | dateArrayFromSeconds(int inSeconds) Given a number of seconds, creates an int[] detailing the months, days, and hours difference as well. int days = (int) (inSeconds / (60 * 60 * 24)); inSeconds -= (days * 60 * 60 * 24); int hours = (int) (inSeconds / (60 * 60)); inSeconds -= (hours * 60 * 60); int minutes = (int) (inSeconds / 60); inSeconds -= (minutes * 60); return new int[] { days, hours, minutes, inSeconds }; |
long | dateDiffToSeconds(final String diff) parse a string to get time span in seconds long secs = 0; final String[] units = diff.split("[.]"); for (final String unit : units) { if (unit.matches("[dhms][0-9]+")) { final char unitdesc = unit.charAt(0); switch (unitdesc) { case 's': secs += Integer.parseInt(unit.replace("s", "")); ... |
long | HoursToSeconds(final float hours) Hours To Seconds return (long) (hours * MINUTES_IN_AN_HOUR * SECONDS_IN_A_MINUTE); |
boolean | isSecondsWholeHour(long secs) is Seconds Whole Hour return (hoursToSecs(secsToHours(secs))) == secs;
|
String | second2time(int seconds) secondtime int hour = seconds / 3600; int other = seconds % 3600; int minute = other / 60; int second = other % 60; StringBuilder sb = new StringBuilder(); if (hour < 10) { sb.append("0"); sb.append(hour); sb.append(":"); if (minute < 10) { sb.append("0"); sb.append(minute); sb.append(":"); if (second < 10) { sb.append("0"); sb.append(second); return sb.toString(); |
int | seconds(int num) seconds return TICKS_PER_SECOND * num;
|
int | seconds(int s) seconds return s * 1000;
|
long | seconds(int seconds) seconds return seconds * ONE_SECOND_IN_MILLIS;
|
String | secondsAfterMidnightToClock(int secondsAfterMidnight) Convert seconds after midnight to 24hr clock time like "06:00:00" return String.format("%02d:%02d:%02d", secondsAfterMidnight / 3600, (secondsAfterMidnight / 60) % 60, secondsAfterMidnight % 60); |