Java Second Get getSecondsFromString(String s)

Here you can find the source of getSecondsFromString(String s)

Description

get Seconds From String

License

LGPL

Declaration

public static int getSecondsFromString(String s) throws NumberFormatException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static int getSecondsFromString(String s) throws NumberFormatException {
        String modifier = "none";

        char c = s.charAt(s.length() - 1);
        modifier = c >= '0' && c <= '9' ? "none" : Character.toString(c).toLowerCase();
        if (!modifier.equals("none")) {
            s = s.substring(0, s.length() - 1);
        }/*from w w  w . j  a v  a2  s . c o  m*/

        int mult = getMultiplierForModifier(modifier);

        return Integer.parseInt(s) * mult;
    }

    public static int getMultiplierForModifier(String modifier) {
        switch (modifier) {
        case "s":
            return 1;
        case "m":
            return 60;
        case "h":
            return 3600;
        case "d":
            return 86400;
        case "w":
            return 604800;
        default:
            return 60;
        }
    }
}

Related

  1. getSecondsAsClock(int time)
  2. getSecondsByDays(int days)
  3. getSecondsForShortString(String string)
  4. getSecondsFromEpoch()
  5. getSecondsFromHMS(String hmsvalue)
  6. getSecondsFromString(String text)
  7. getSecondsFromStringDuration(String duration)
  8. getSecondSimpleType(String completeType)
  9. getSecondsInDDHHMMSS(int s)