Java tutorial
//package com.java2s; /** * Plugin UltraHardcore (UHPlugin) * Copyright (C) 2013 azenet * Copyright (C) 2014 Amaury Carrade * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see [http://www.gnu.org/licenses/]. */ public class Main { public static int string2Time(String text) { String[] splitted = text.split(":"); if (splitted.length > 3) { throw new IllegalArgumentException( "Badely formatted string in string2time, formats allowed are mm, mm:ss or hh:mm:ss."); } if (splitted.length == 1) { // "mm" return Integer.valueOf(splitted[0]) * 60; } else if (splitted.length == 2) { // "mm:ss" return Integer.valueOf(splitted[0]) * 60 + Integer.valueOf(splitted[1]); } else { // "hh:mm:ss" return Integer.valueOf(splitted[0]) * 3600 + Integer.valueOf(splitted[1]) * 60 + Integer.valueOf(splitted[2]); } } }