Java Date Format Pattern subtraiHora(String horaFim, String horaIni, String formatoHora)

Here you can find the source of subtraiHora(String horaFim, String horaIni, String formatoHora)

Description

Retorna o numero de minutos

License

Open Source License

Parameter

Parameter Description
horaFim a parameter
horaIni a parameter
formatoHora - hh:mm:ss

Declaration

public static double subtraiHora(String horaFim, String horaIni, String formatoHora) 

Method Source Code

//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;
    }
}

Related

  1. isEqual(String d1, String d2, String format)
  2. isValidFormat(String format, String value)
  3. log(String format, Object... args)
  4. logFormat(String msg)
  5. subFiles(String formatString, File[] files)
  6. sysdateStringddMMyyyyhhmmss()
  7. toThreadSafeFormat(final String format)
  8. traceInformation(String message)