Difference between current date and later date, late minutes, tracking

0

I want to calculate the difference in minutes between one date and another, however when this difference is greater than 45, I want it to say that it goes "x minutes late", if they pass "and" minute (s) should show: " x + and late minutes " I currently have this, it works perfectly when the current date is less than the date that must be fulfilled:

 Date fechaactual = new Date();
    long diff = trackingfecha.getTime() - fechaactual.getTime();
    long diferenciaminutos = diff / (60 * 1000);
    RunneableUpdateUI run = new RunneableUpdateUI();
    if(diffMinutes < 45.0) {
        if(diffMinutes >= 0) {
            //Se muestran los minutos restantes para llegar a la fecha trackingfecha 
            StringBuffer buffer = new StringBuffer();
            buffer.append("te quedan ");
            String minutes = String.format("%02d", diffMinutes);
            buffer.append(minutes);
            buffer.append(" min");
            run.toUpdateValue = buffer.toString();
        } else {
           //Actualmente aqui es el problema, siempre que hago la operación muestra números completamente incongruentes, como 200 minutos tarde. Incluso cuando la diferencia es de solamente 60 minutos.
            StringBuffer buffer = new StringBuffer();
            String minutes = String.format("%02d", Math.abs(diffMinutes));
            buffer.append(minutes);
            buffer.append(" min tarde");
            run.toUpdateValue = buffer.toString();
        }
        timerHandler.post(run);
    }

I want to calculate the time it takes to reach a specific date and if it goes beyond this specific date, show how late it is going.

    
asked by Dinorah Tovar 11.04.2017 в 00:26
source

1 answer

0

Your code looks good, what I do not understand is where you get the variable diffMinutes if you previously calculate 'differenceminutes.

    RunneableUpdateUI run = new RunneableUpdateUI();
    if(Math.abs(diferenciaminutos) < 45 ) { // muestra valores solamente cuando la diferencia es menos de 45 min
        if(diferenciaminutos >= 0) {
            //Se muestran los minutos restantes para llegar a la fecha trackingfecha 
            StringBuffer buffer = new StringBuffer();
            buffer.append("te quedan ");
            String minutes = String.format("%02d", diferenciaminutos);
            buffer.append(minutes);
            buffer.append(" min");
            run.toUpdateValue = buffer.toString();
        } else {
           //Actualmente aqui es el problema, siempre que hago la operación muestra números completamente incongruentes, como 200 minutos tarde. Incluso cuando la diferencia es de solamente 60 minutos.
            StringBuffer buffer = new StringBuffer();
            String minutes = String.format("%02d", -diferenciaminutos); // negativo, porque < 0
            buffer.append(minutes);
            buffer.append(" min tarde");
            run.toUpdateValue = buffer.toString();
        }
    
answered by 11.04.2017 в 03:01