-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockExamples.java
More file actions
38 lines (32 loc) · 1011 Bytes
/
ClockExamples.java
File metadata and controls
38 lines (32 loc) · 1011 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
33
34
35
36
37
38
import java.time.Clock;
import java.time.Duration;
public class ClockExamples {
public static void main(String[] args) {
System.out.println("Clock Get Zone Example");
clockGetZoneExample();
System.out.println("Clock Instant Example");
clockInstantExample();
System.out.println("Clock System UTC Example");
clockSystemUTCExample();
System.out.println("Clock System UTC Offset Example");
clockOffsetExample();
}
public static void clockGetZoneExample(){
Clock c = Clock.systemDefaultZone();
System.out.println(c.getZone());
}
public static void clockInstantExample(){
Clock c = Clock.systemUTC();
System.out.println(c.instant());
}
public static void clockSystemUTCExample(){
Clock c = Clock.systemUTC();
System.out.println(c.instant());
}
public static void clockOffsetExample(){
Clock c = Clock.systemUTC();
Duration d = Duration.ofHours(5);
Clock clock = Clock.offset(c, d);
System.out.println(clock.instant());
}
}