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; duration = duration.toUpperCase().trim(); int days = duration.indexOf('D'); int hours = duration.indexOf('H'); int minutes = duration.indexOf('M'); int seconds = duration.indexOf('S'); int lastIndex = 0; try {/*from w w w . j ava2 s . co m*/ if (days > 0) { durationMillis += TimeUnit.DAYS .toMillis(Long.parseLong(duration.substring(lastIndex, days).trim())); lastIndex = days + 1; } if (hours > 0) { durationMillis += TimeUnit.HOURS .toMillis(Long.parseLong(duration.substring(lastIndex, hours).trim())); lastIndex = hours + 1; } if (minutes > 0) { durationMillis += TimeUnit.MINUTES .toMillis(Long.parseLong(duration.substring(lastIndex, minutes).trim())); lastIndex = minutes + 1; } if (seconds > 0) { durationMillis += TimeUnit.SECONDS .toMillis(Long.parseLong(duration.substring(lastIndex, seconds).trim())); lastIndex = seconds + 1; } if (lastIndex < duration.length()) { durationMillis += Long.parseLong(duration.substring(lastIndex)); } } catch (NumberFormatException nfe) { throw new IllegalArgumentException("Cannot parse string: '" + duration + "'", nfe); } return durationMillis; } }