Here you can find the source of parseTime(String input)
public static long parseTime(String input)
//package com.java2s; //License from project: Open Source License import java.util.Locale; import java.util.Scanner; public class Main { public static long parseTime(String input) { Scanner scanner = new Scanner(input.trim()); scanner.useLocale(Locale.ENGLISH); long time; // 00:00.000 if (input.contains(":")) { scanner.useDelimiter(":"); if (!scanner.hasNextLong()) { return 0; }// www . j av a 2 s . co m long minutes = scanner.nextLong(); if (minutes < 0) { return 0; } if (!scanner.hasNextDouble()) { return 0; } double seconds = scanner.nextDouble(); if (seconds < 0.0 || seconds >= 60.0) { return 0; } time = (long) (60000 * minutes + 1000 * seconds); } // 00.000 else { if (!scanner.hasNextDouble()) { return 0; } double seconds = scanner.nextDouble(); if (seconds < 0.0) { return 0; } time = (long) (1000 * seconds); } return time; } }