Java Second Get getUnitLengthSeconds(String unit)

Here you can find the source of getUnitLengthSeconds(String unit)

Description

get Unit Length Seconds

License

Open Source License

Parameter

Parameter Description
unit A string representing the unit. This accepts seconds, minutes, hours and days, and should be constant across calendar systems.

Return

The length of the given unit in seconds.

Declaration

public static int getUnitLengthSeconds(String unit) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from ww w . ja v  a 2 s .  c  om*/
     * @param unit
     *            A string representing the unit. This accepts seconds, minutes,
     *            hours and days, and should be constant across calendar
     *            systems.
     * @return The length of the given unit in seconds.
     */
    public static int getUnitLengthSeconds(String unit) {
        unit = unit.trim();
        if (unit.equals("seconds") || unit.equals("second") || unit.equals("secs") || unit.equals("sec")
                || unit.equals("s")) {
            return 1;
        } else if (unit.equals("minutes") || unit.equals("minute") || unit.equals("mins") || unit.equals("min")) {
            return 60;
        } else if (unit.equals("hours") || unit.equals("hour") || unit.equals("hrs") || unit.equals("hr")
                || unit.equals("h")) {
            return 60 * 60;
        } else if (unit.equals("days") || unit.equals("day") || unit.equals("d")) {
            return 60 * 60 * 24;
        } else {
            throw new IllegalArgumentException("Unrecognized unit: " + unit);
        }
    }
}

Related

  1. getTimeFromSeconds(int seconds)
  2. getTimeInSecondResolution(long timeMillis)
  3. getTimeSeconds(String time)
  4. getTimeStringFromSeconds(int totalSeconds)
  5. getTokenRenewIntervalInSeconds(int tokenValidityInSeconds)
  6. getUnixTimeSeconds()
  7. getUSeconds(int time)
  8. getValidCodeSecond()
  9. timeToSeconds(String targetTime)