forked from dilipsundarraj1/java-8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstantExample.java
More file actions
32 lines (19 loc) · 959 Bytes
/
Copy pathInstantExample.java
File metadata and controls
32 lines (19 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.learnJava.dates;
import java.time.*;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
public class InstantExample {
public static void main(String[] args) {
Instant instant = Instant.now(); // Represents the date and time in unix timestamp in a machine readable format.
System.out.println(instant);
// Interface1 day has 86400 seconds.
// What is EPOCH ? -> equal to Jan. 1st 1970
System.out.println("getEpochSecond : " +instant.getEpochSecond()); //Jan. 1st 1970 -> 0 seconds
//it does not support any of the methods which represents the time in human readable format.
Instant instant1 =Instant.ofEpochMilli(0);
System.out.println("instant1 : " + instant1);
Instant instant2 = Instant.now();
Duration duration = Duration.between(instant,instant2);
System.out.println("getNano : " + duration.getNano());
}
}