Here you can find the source of getTimeAsSeconds(String value)
Parameter | Description |
---|---|
NumberFormatException | an exception |
public static long getTimeAsSeconds(String value)
//package com.java2s; public class Main { /**//from w ww .j a v a2 s. co m * A time can be passed in as a long in millis, or with a unit on it, like '60s'. * Possible units are * ms, millis seconds * s, seconds * m, minutes * h, hours * * @return The value of the property, or what is in default. * @throws NumberFormatException */ public static long getTimeAsSeconds(String value) { return getTimeAsMillis(value) / 1000; } /** * A time can be passed in as a long in millis, or with a unit on it, like '60s'. * Possible units are * ms, millis seconds * s, seconds * m, minutes * h, hours * * @return The value of the property, or what is in default. * @throws NumberFormatException */ public static long getTimeAsMillis(String value) throws NumberFormatException { if (value.indexOf("ms") != -1) { return Long.parseLong(value.substring(0, value.indexOf("ms"))); } else if (value.indexOf("s") != -1) { return 1000 * Long.parseLong(value.substring(0, value.indexOf("s"))); } else if (value.indexOf("m") != -1) { return 1000 * 60 * Long.parseLong(value.substring(0, value.indexOf("m"))); } else if (value.indexOf("h") != -1) { return 1000 * 60 * 60 * Long.parseLong(value.substring(0, value.indexOf("h"))); } else { return 1000 * Long.parseLong(value); } } }