Java String Value Of valueOf(String s)

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

Description

value Of

License

Open Source License

Declaration

public static long valueOf(String s) 

Method Source Code

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

public class Main {
    public static long valueOf(String s) {
        long time = 0L;

        for (String st : s.split(" ")) {
            if (st.endsWith("d")) {
                time += Long.valueOf(st.substring(0, st.length() - 1)) * 86400L;
                continue;
            }//from   w  w w.j a v a2s  . c  o  m

            if (st.endsWith("s")) {
                time += Long.valueOf(st.substring(0, st.length() - 1));
                continue;
            }

            if (st.endsWith("m")) {
                time += Long.valueOf(st.substring(0, st.length() - 1)) * 60L;
                continue;
            }

            if (st.endsWith("h")) {
                time += Long.valueOf(st.substring(0, st.length() - 1)) * 3600L;
                continue;
            }

            throw new NumberFormatException(st + " is not a time value!");
        }

        return time;
    }
}

Related

  1. valueOf(String format, String value)
  2. valueOf(String s)
  3. valueOf(String s)
  4. valueOf(String s)
  5. valueOf(String s)
  6. valueOf(String s, Class e)
  7. valueOf(String s, int def)
  8. valueOf(String str)
  9. valueOf(String str)