-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareTwoInstants.java
More file actions
22 lines (17 loc) · 869 Bytes
/
Copy pathCompareTwoInstants.java
File metadata and controls
22 lines (17 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.codecafe.java8.datetime;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
public class CompareTwoInstants {
public static void main(String[] args) {
Instant now = Instant.now();
Instant aWeekBefore = now.minus(7, ChronoUnit.DAYS);
System.out.println("---------------------------------------------");
System.out.println("Now : " + now);
System.out.println("A week before : " + aWeekBefore);
System.out.println("---------------------------------------------");
System.out.println("now.compareTo(aWeekBefore) = " + now.compareTo(aWeekBefore));
System.out.println("aWeekBefore.compareTo(aWeekBefore) = " + aWeekBefore.compareTo(aWeekBefore));
System.out.println("aWeekBefore.compareTo(now) = " + aWeekBefore.compareTo(now));
System.out.println("---------------------------------------------");
}
}