Here you can find the source of getSecondsFromHMS(String hmsvalue)
Parameter | Description |
---|---|
hmsvalue | La valeur temporelle telle que H:MM:SS avec autant de H que l'on veut. On peut utiliser ce que l'on veut comme separateur. |
public static int getSecondsFromHMS(String hmsvalue)
//package com.java2s; /*/*from ww w. j av a 2s . c o m*/ * This file is part of Java Tools for hdsdi3g'. * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * any later version. * * This library 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 Lesser General Public License for more details. * * Copyright (C) hdsdi3g for hd3g.tv 2009-2012 * */ public class Main { /** * Convertie quelque chose comme 123:45:12 donne 445512 * @param hmsvalue La valeur temporelle telle que H:MM:SS avec autant de H que l'on veut. * On peut utiliser ce que l'on veut comme separateur. * @return la valeur convertie en secondes */ public static int getSecondsFromHMS(String hmsvalue) { // 00000:00:00 if (hmsvalue.length() < 7) { return -1; } try { int secs = Integer.valueOf(hmsvalue.substring(hmsvalue.length() - 2, hmsvalue.length())); int mins = Integer.valueOf(hmsvalue.substring(hmsvalue.length() - 5, hmsvalue.length() - 3)); int hours = Integer.valueOf(hmsvalue.substring(0, hmsvalue.length() - 6)); return (hours * 3600) + (mins * 60) + secs; } catch (Exception e) { } return -1; } }