File tree 1 file changed +21
-0
lines changed
java-dates/src/test/java/com/baeldung/date
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 8
8
import java .time .LocalDate ;
9
9
import java .time .LocalDateTime ;
10
10
import java .time .Period ;
11
+ import java .time .temporal .ChronoUnit ;
11
12
import java .util .Date ;
12
13
import java .util .Locale ;
13
14
import java .util .TimeZone ;
@@ -51,6 +52,16 @@ public void givenTwoDateTimesInJava8_whenDifferentiating_thenWeGetSix() {
51
52
assertEquals (diff , 6 );
52
53
}
53
54
55
+ @ Test
56
+ public void givenTwoDateTimesInJava8_whenDifferentiatingInSeconds_thenWeGetTen () {
57
+ LocalDateTime now = LocalDateTime .now ();
58
+ LocalDateTime tenSecondsLater = now .plusSeconds (10 );
59
+
60
+ long diff = ChronoUnit .SECONDS .between (now , tenSecondsLater );
61
+
62
+ assertEquals (diff , 10 );
63
+ }
64
+
54
65
@ Test
55
66
public void givenTwoZonedDateTimesInJava8_whenDifferentiating_thenWeGetSix () {
56
67
LocalDateTime ldt = LocalDateTime .now ();
@@ -60,6 +71,16 @@ public void givenTwoZonedDateTimesInJava8_whenDifferentiating_thenWeGetSix() {
60
71
assertEquals (diff , 6 );
61
72
}
62
73
74
+ @ Test
75
+ public void givenTwoDateTimesInJava8_whenDifferentiatingInSecondsUsingUntil_thenWeGetTen () {
76
+ LocalDateTime now = LocalDateTime .now ();
77
+ LocalDateTime tenSecondsLater = now .plusSeconds (10 );
78
+
79
+ long diff = now .until (tenSecondsLater , ChronoUnit .SECONDS );
80
+
81
+ assertEquals (diff , 10 );
82
+ }
83
+
63
84
@ Test
64
85
public void givenTwoDatesInJodaTime_whenDifferentiating_thenWeGetSix () {
65
86
org .joda .time .LocalDate now = org .joda .time .LocalDate .now ();
You can’t perform that action at this time.
0 commit comments