Find the number of minutes in a HH:MM:SS time string

From CodeCodex

Revision as of 19:28, 14 September 2006 by 206.160.140.2 (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Implementations

Java

	/**
	 * Turns a period of time into the number of minutes containted there in (eg. 06:30:15 returns 360.25)
	 * @param hourFormat The string containing the hour format "HH:MM:SS"
	 * @return The number of minutes represented, or -1 if the date could not be processed.
	 */
	public static double parseTimeToMinutes(String hourFormat) {
		
		double minutes = 0;
		String[] split = hourFormat.split(":");
		
		try {
			
			minutes += Double.valueOf(split[0])*60;
			minutes += Double.valueOf(split[1]);
			minutes += Double.valueOf(split[2])/60;
			return minutes;
		
		} catch (Exception e) {
			return -1;
		}
		
	}