Answers for "java calculate date difference"

12

java find time between two dates

public static String getAge(String birthdate) throws ParseException {
		LocalDate parsed = LocalDate.parse("1970-01-01");
		LocalDate current = LocalDate.now();
		
		Period p = Period.between(parsed, current);

  		// Returns time between date and now
		return p.getYears() + " Years, " + p.getMonths() + " Months, " + p.getDays() + " Days";
	}
Posted by: Guest on March-11-2021
2

date difference in minutes java

long diff = d2.getTime() - d1.getTime();//as given

long seconds = TimeUnit.MILLISECONDS.toSeconds(diff);
long minutes = TimeUnit.MILLISECONDS.toMinutes(diff);
Posted by: Guest on August-21-2020
2

java calculate time difference

You can use calendar
calendarMilis = c.timeInMillis.toInt() - System.currentTimeMillis().toInt()
Posted by: Guest on July-27-2021
-1

java localdate subtract two dates

@Test
public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix() {
    LocalDate now = LocalDate.now();
    LocalDate sixDaysBehind = now.minusDays(6);
 
    Period period = Period.between(now, sixDaysBehind);
    int diff = period.getDays();
 
    assertEquals(diff, 6);
}
Posted by: Guest on March-21-2020

Code answers related to "java calculate date difference"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language