Here you can find the source of subtraiHora(String horaFim, String horaIni, String formatoHora)
Parameter | Description |
---|---|
horaFim | a parameter |
horaIni | a parameter |
formatoHora | - hh:mm:ss |
public static double subtraiHora(String horaFim, String horaIni, String formatoHora)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.TimeZone; public class Main { /**// www. j a v a 2s .co m * Retorna o numero de minutos * * @param horaFim * @param horaIni * @param formatoHora * - hh:mm:ss * @return */ public static double subtraiHora(String horaFim, String horaIni, String formatoHora) { SimpleDateFormat formatter = new SimpleDateFormat(formatoHora); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); double min_1 = 0; double min_2 = 0; double result = 0; min_1 = getHoras(horaFim, formatter); min_2 = getHoras(horaIni, formatter); result = (min_1 - min_2) * 60; if (min_1 < min_2) result = (min_2 - min_1) * 60; if (result == 0) { return 0; } double x = ((result / 3600) / 1000); return x * 60; } private static long getHoras(String hora, SimpleDateFormat formatter) { String hor = hora.substring(0, 2); String min = hora.substring(3, 5); String sec = hora.substring(6); int intHor = Integer.parseInt(hor); int intMin = Integer.parseInt(min); int intSec = Integer.parseInt(sec); long ret = (intSec * 1000) + ((intMin * 60) * 1000) + (((intHor * 60) * 60) * 1000); long rhora = ret / 60; return rhora; } }