Code to get diffrence between two days in the form of totalHours and Days

 
long diffInMillisec = eventdate.getTime() -eventEndDate.getTime();
         long diffInSec = TimeUnit.MILLISECONDS.toSeconds(diffInMillisec);
         System.out.println("-----------diffInSec------------"+diffInSec);
         
         long diffInHours = TimeUnit.HOURS.toSeconds(diffInMillisec);
         System.out.println("-----------diffInHours------------"+diffInHours);
         
         long seconds = diffInSec % 60;
         System.out.println("-----------seconds------------"+seconds);
         diffInSec/= 60;
         long minutes =diffInSec % 60;
         System.out.println("-----------minutes------------"+minutes);
         diffInSec /= 60;
         long hours = diffInSec % 24;
         System.out.println("-----------hours------------"+hours);
         diffInSec /= 24;
         long days = diffInSec;
         System.out.println("-----------days------------"+days);
         
         long totalHours=(days*24)+hours;
         System.out.println("-----------Total no.of Hours------------"+totalHours);

Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

Best working code to set Date limits on Date Picker Dialog,in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard