/** * Fetches the Time out of the String.
* Can handle modifiers like 's', 'm', 'h' and 'd'
* to calculate other Times. (ex. m -> minute)
* Default handles Input as Milliseconds * @param time * @return */ public static Long getTime(String time) { try { if (time.length() == 0) return null; if (time.matches("[0-9]+")) return Long.valueOf(time); if (time.length() == 1) return null; long returnTime = 0; int lastLetter = 0; for (int i = 0; i < time.length(); i++) { String character = String.valueOf(time.charAt(i)).toLowerCase(); if (!character.matches("[0-9]")) { Long fetchedTime = ModUtils.getLong(time.substring(lastLetter, i)); if (character.equals("s")) { returnTime += (fetchedTime * 1000); } else if (character.equals("m")) { returnTime += ((fetchedTime * 60) * 1000); } else if (character.equals("h")) { returnTime += ((fetchedTime * 60 * 60) * 1000); } else if (character.equals("d")) { returnTime += ((fetchedTime * 60 * 60 * 24) * 1000); } else { return null; } lastLetter = i; } else { if (i == time.length()) { returnTime += Long.getLong(time.substring(lastLetter, i)); } } } return returnTime; } catch (Exception exc) { exc.printStackTrace(); } return null; }