Java Best Way Date Difference Code Example

Snippet 1
public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix() {
    LocalDate now =;
    LocalDate sixDaysBehind = now.minusDays(6);
    Period period = Period.between(now, sixDaysBehind);
    int diff = period.getDays();
    assertEquals(diff, 6);

Similar Snippets

Creating Java Main Method Code Example - java

Find Duplicates In Arraylist Java Code Example - java

Java Creat A Folder Code Example - java

Firestore Find Doc And Set Data Code Example - java

Create Copy Of Array From Another Array Code Example - java