Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { /** * Takes a string of the form [HH:]MM:SS[.mmm] and converts it to * milliseconds. * * @throws java.lang.NumberFormatException if the number segments contain invalid numbers. */ public static long parseTimeString(final String time) { String[] parts = time.split(":"); long result = 0; int idx = 0; if (parts.length == 3) { // string has hours result += Integer.valueOf(parts[idx]) * 3600000L; idx++; } if (parts.length >= 2) { result += Integer.valueOf(parts[idx]) * 60000L; idx++; result += (Float.valueOf(parts[idx])) * 1000L; } return result; } }