Here you can find the source of timespanToMillis(String timeString)
public static long timespanToMillis(String timeString) throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static long timespanToMillis(String timeString) throws ParseException { Pattern pattern = Pattern.compile("(-?\\d+\\.?\\d*)([\\w]{0,1})", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(timeString); if (matcher.matches()) { double baseMillis = Double.parseDouble(matcher.group(1)); String unit = matcher.group(2).toLowerCase(); if (unit.equals("d") || unit.length() == 0) { return (long) (baseMillis * 1000 * 3600 * 24); } else if (unit.equals("h")) { return (long) (baseMillis * 1000 * 3600); } else if (unit.equals("w")) { return (long) (baseMillis * 1000 * 3600 * 24 * 7); } else if (unit.equals("m")) { return (long) (baseMillis * 1000 * 3600 * 24 * 30); } else if (unit.equals("y")) { return (long) (baseMillis * 1000 * 3600 * 24 * 360); }/* ww w . j a v a 2 s . com*/ } throw new ParseException(timeString, 0); } }