Here you can find the source of timeStringToSeconds(String input)
public static int timeStringToSeconds(String input)
//package com.java2s; //License from project: Open Source License public class Main { public static int timeStringToSeconds(String input) { int result = 0; String number = ""; for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (Character.isDigit(c)) { number += c;/*from ww w. j av a2s. c o m*/ } else if (Character.isLetter(c) && !number.isEmpty()) { result += convert(Integer.parseInt(number), c); number = ""; } } if (!number.equals("")) { result += Integer.parseInt(number); } return result; } private static long convert(int value, char unit) { switch (unit) { case 'd': return value * 60 * 60 * 24; case 'h': return value * 60 * 60; case 'm': return value * 60; case 's': return value; } return value; } }