Java Utililty Methods Second Calculate

List of utility methods to do Second Calculate

Description

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

Method

longcomputeStartOfNextSecond(long now)
compute Start Of Next Second
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(now));
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.SECOND, 1);
return cal.getTime().getTime();
longgetMillisecond(long num, int unit)
get Millisecond
if (unit == Calendar.SECOND) {
    return num * 1000;
} else if (unit == Calendar.MINUTE) {
    return num * 60 * 1000;
} else if (unit == Calendar.HOUR_OF_DAY) {
    return num * 3600 * 1000;
throw new IllegalArgumentException("unknown time unit: " + unit);
...
intgetSecond(long t)
get Second
Calendar cld = Calendar.getInstance();
if (t > 0) {
    cld.setTime(new java.util.Date(t));
return cld.get(Calendar.SECOND);
intgetSecond(String s)
get Second
if (s == null || s.length() < 18) {
    return 0;
return Integer.parseInt(s.substring(16, 18));
DatenextSecond(int second)
next Second
Calendar now = now();
now.set(Calendar.SECOND, now.get(Calendar.SECOND) + second);
return now.getTime();
DatesecondsLater(Integer seconds)
Get date for number of seconds later
return forCalendarDiff(Calendar.SECOND, seconds);