Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

find difference in days between two dates java

String dateStart = "01/14/2015 08:29:58";
String dateStop = "01/15/2015 11:31:48";

//HH converts hour in 24 hours format (0-23), day calculation
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

Date d1 = null;
Date d2 = null;

d1 = format.parse(dateStart);
d2 = format.parse(dateStop);

//in milliseconds
long diff = d2.getTime() - d1.getTime();

long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000);

System.out.print(diffDays + " days, ");
System.out.print(diffHours + " hours, ");
System.out.print(diffMinutes + " minutes, ");
System.out.print(diffSeconds + " seconds.");
Comment

java number of days between dates

LocalDate start = LocalDate.parse("2020-11-03");
LocalDate end = LocalDate.parse("2020-12-15");

long diff = DAYS.between(start, end);
Comment

java days between two dates

LocalDate dateBefore;
LocalDate dateAfter;
long daysBetween = DAYS.between(dateBefore, dateAfter);
Comment

java 8 datediff in days

LocalDate dateBefore;
LocalDate dateAfter;
long daysBetween = DAYS.between(dateBefore, dateAfter);
Comment

PREVIOUS NEXT
Code Example
Java :: javax notblank not working 
Java :: android settextcolor programmatically 
Java :: activity as a splash screen java code 
Java :: java elapsedTime 
Java :: update value in hashmap java 
Java :: big screen jframe 
Java :: how can i to do java home 
Java :: populate arraylist java one line 
Java :: from string to double andoird studio 
Java :: java print stacktrace to file 
Java :: add days to date java 
Java :: joptionpane hello world 
Java :: javaee .jsp get value of object with EL 
Java :: how to download java on mint 
Java :: events that people think are unlikely but actually have high probability 
Java :: similarity between abstract class and interface java 
Java :: java int to hex fixed length 
Java :: java console write 
Java :: set vs list java 
Java :: Captain Disillusion age 
Java :: android java remove action bar 
Java :: sleep() java 
Java :: java all alphabet characters 
Java :: java initialize float to zero 
Java :: java get unix timestamp 
Java :: java add listent to button 
Java :: assert system.out.println 
Java :: reverse string in java 
Java :: get file extension java 
Java :: making android activity fullscreen android studio 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =