Here you can find the source of getTimeAsMillis(String value)
Parameter | Description |
---|---|
NumberFormatException | an exception |
public static long getTimeAsMillis(String value) throws NumberFormatException
//package com.java2s; public class Main { /**/*from w w w .j a va 2 s .c o 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 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); } } }