File tree Expand file tree Collapse file tree
java-dates/src/test/java/com/baeldung/date
src/test/java/com/baeldung Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import java .text .ParseException ;
66import java .text .SimpleDateFormat ;
77import java .time .Duration ;
8+ import java .time .LocalDate ;
89import java .time .LocalDateTime ;
10+ import java .time .Period ;
911import java .util .Date ;
1012import java .util .Locale ;
1113import java .util .TimeZone ;
@@ -26,6 +28,17 @@ public void givenTwoDatesBeforeJava8_whenDifferentiating_thenWeGetSix() throws P
2628
2729 assertEquals (diff , 6 );
2830 }
31+
32+ @ Test
33+ public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix () {
34+ LocalDate now = LocalDate .now ();
35+ LocalDate sixDaysBehind = now .minusDays (6 );
36+
37+ Period period = Period .between (now , sixDaysBehind );
38+ int diff = period .getDays ();
39+
40+ assertEquals (diff , 6 );
41+ }
2942
3043 @ Test
3144 public void givenTwoDateTimesInJava8_whenDifferentiating_thenWeGetSix () {
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 665665 <module >dubbo</module >
666666 <module >flyway</module >
667667 <!-- <module>grpc</module> --><!-- protobuf-maven-plugin filecopy failure -->
668- <module >java-difference-date</module >
669668 <!-- <module>JGit</module> --><!-- Unit test failure -->
670669 <module >jni</module >
671670 <module >jooby</module >
11381137 <module >dubbo</module >
11391138 <module >flyway</module >
11401139 <!-- <module>grpc</module> --><!-- protobuf-maven-plugin filecopy failure -->
1141- <module >java-difference-date</module >
11421140 <!-- <module>JGit</module> --><!-- Unit test failure -->
11431141 <module >jni</module >
11441142 <module >jooby</module >
You can’t perform that action at this time.
0 commit comments