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

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

PREVIOUS NEXT
Code Example
Java :: retrofit dependencies in android studio kotlin 
Java :: Java Using forName() method 
Java :: selet all elemnts 
Java :: what is the difference between sc.nextLine() and sc.next() in java 
Java :: how to get system date in android 
Java :: minecraft java 
Java :: duplicate local variable in java 
Java :: java ModelMapper class 
Java :: bukkit scheduled task 
Java :: how to read a text file in java 
Java :: android hide status bar and action bar daynamically 
Java :: java iterate through map 
Java :: java print text 
Java :: how to make hello world in java 
Java :: java get random char from alphabet 
Java :: offsetdattime to date 
Java :: how to iterate hashmap java 
Java :: java scanner input float 
Java :: how to round up in java 
Java :: recyclerview stop scrolling 
Java :: java 11 download 64 bit 
Java :: data java 
Java :: all devisor of a number java 
Java :: how to create an array in java 
Java :: How to do press enter to continue in java 
Java :: why java platform independent 
Java :: jframe actionlistener 
Java :: 2d arraylist in java 
Java :: java convert float to int 
Java :: java add button 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =