alcatrazbr
9/24/2016 - 10:45 AM

joda time diff diferença de tempo

joda time diff diferença de tempo

System.currentTimeMillis()

long startTime = System.currentTimeMillis();
// ... do something ...
long estimatedTime = System.currentTimeMillis() - startTime;



Date dtLastPosition =  new Date(); // start
Date Now = new Date(); // end


long diff = Now.getTime() - dtLastPosition.getTime();
long diffMinutes = diff / (60 * 1000) % 60;
String strIni = "11/30/2016 14:00:58";
String strFim = "11/30/2016 16:30:58";

DateTimeFormatter dtf = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss");

DateTime ini = dtf.parseDateTime(strIni);
DateTime fim = dtf.parseDateTime(strFim);

DateTimeFormatter dtfOut = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss");


System.out.print(Days.daysBetween(ini, fim).getDays() + " days, ");
System.out.print(Hours.hoursBetween(ini, fim).getHours() % 24 + " hours, ");
System.out.print(Minutes.minutesBetween(ini, fim).getMinutes() % 60 + " minutes, ");
System.out.print(Seconds.secondsBetween(ini, fim).getSeconds() % 60 + " seconds."); 

long diffInMillis = (fim.getMillis() - ini.getMillis());
        int minutos = (int) (diffInMillis / 1000 /60);
        System.out.println(
        	    String.format("%d Minutes: %d:%02d Hours", minutos, (minutos/60), (minutos%60)));
        /*hrs*/
        System.out.println(((diffInMillis / 1000) / 60)/60 + " horas \n");
        /*minutos*/
        System.out.println(((diffInMillis / 1000) / 60)%60 + " minutos \n");
        
System.out.println((diffInMillis/60)/1000);

System.out.println("Ini " + dtfOut.print(ini));
System.out.println("Fim " + dtfOut.print(fim));