forked from LuigiCortese/java-certification-ocp8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.java
77 lines (57 loc) · 1.65 KB
/
App.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package net.devsedge.datetime.basics;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
/**
*
* @author Luigi Cortese
*
*/
public class App {
public static void main(String[] args) {
/*
* Times
*/
LocalDate localDate = LocalDate.now();
LocalTime localTime = LocalTime.now();
LocalDateTime localDateTime = LocalDateTime.now();
/*
* ZoneOffset: a time-zone offset from Greenwich/UTC, such as +02:00.
*/
ZoneOffset zoneOffset = ZoneOffset.of("+2");
/*
* Offset[Date]Time = Local[Date]Time + ZoneOffset
*/
OffsetTime offsetTime = OffsetTime.of(localTime,zoneOffset);
OffsetDateTime offsetDateTime = OffsetDateTime.of(localDateTime,zoneOffset);
/*
* ZoneId: a time-zone ID, such as Europe/Paris.
*/
ZoneId zoneId = ZoneId.of(zoneOffset.getId());
/*
* ZonedDateTime = LocalDateTime
*/
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zoneId);
/*
* Period: in terms of years, months and days
*/
Period period = Period.of(1,1,1);
/*
* Duration: in terms of hours, minutes and seconds
*/
Duration duration = Duration.of(1,ChronoUnit.MINUTES);
/*
* Instant: in terms of seconds elapsed from epoch time
*/
Instant instant = Instant.ofEpochSecond(119);
}
}