Here you can find the source of string2Millis(String duration)
public static long string2Millis(String duration)
//package com.java2s; //License from project: Apache License import java.util.concurrent.TimeUnit; public class Main { public static long string2Millis(String duration) { long durationMillis = 0; try {/* w w w. ja v a 2 s . c o m*/ durationMillis = Long.parseLong(duration); } catch (NumberFormatException nfe) { int indexOfM = duration.toUpperCase().indexOf('M'); if (indexOfM > 0) { durationMillis = Long.parseLong(duration.substring(0, indexOfM)); durationMillis = TimeUnit.MINUTES.toMillis(durationMillis); } else { int indexOfS = duration.toUpperCase().indexOf('S'); if (indexOfS > 0) { durationMillis = Long.parseLong(duration.substring(0, indexOfS)); durationMillis = TimeUnit.SECONDS.toMillis(durationMillis); } else { throw new IllegalArgumentException("Cannot parse string: '" + duration + "' Supported formats: '321321' (millis), '3m' (minutes) or '75s' (seconds)"); } } } return durationMillis; } }