Java TimeUnit Convert convertToSecond(int interval, TimeUnit unit)

Here you can find the source of convertToSecond(int interval, TimeUnit unit)

Description

convert To Second

License

Open Source License

Declaration

public static int convertToSecond(int interval, TimeUnit unit) throws UnsupportedDataTypeException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;
import javax.activation.UnsupportedDataTypeException;

import org.joda.time.DateTimeConstants;

public class Main {
    public static int convertToSecond(int interval, TimeUnit unit) throws UnsupportedDataTypeException {
        switch (unit) {
        case DAYS:
            return interval * DateTimeConstants.SECONDS_PER_DAY;
        case HOURS:
            return interval * DateTimeConstants.SECONDS_PER_HOUR;
        case MINUTES:
            return interval * DateTimeConstants.SECONDS_PER_MINUTE;
        case SECONDS:
            return interval;
        case MILLISECONDS:
            return interval / DateTimeConstants.MILLIS_PER_SECOND;
        default://from  ww w.j  a v  a2s.  c o m
            break;
        }

        throw new UnsupportedDataTypeException();
    }
}

Related

  1. convertReportingPeriod(long profilePeriod, TimeUnit profileTimeUnit, long reportingPeriod, TimeUnit reportingTimeUnit)
  2. convertTo(long a, TimeUnit from, TimeUnit to)
  3. convertToDouble(long fromTime, TimeUnit fromTimeUnit, TimeUnit toTimeUnit)
  4. convertToMillis(long waitTime, TimeUnit timeUnit)
  5. convertToMilliseconds(TimeUnit timeUnit, long seed)
  6. durationToMillis(final long val, final TimeUnit unit)
  7. getDateRelativeToNow(TimeUnit timeUnit, long amount)
  8. getRemainingTimeToday(final TimeUnit timeUnit)
  9. hoursToUnit(double hours, TimeUnit destinationUnit)