@@ -48,14 +48,30 @@ val datetimeInSystemZone: LocalDateTime = currentMoment.toLocalDateTime(TimeZone
48
48
```
49
49
50
50
` LocalDateTime ` instance exposes familiar components of the Gregorian calendar:
51
- ` year ` , ` month ` , ` dayOfMonth ` , ` hour ` , and so on up to ` nanosecond ` .
51
+ ` year ` , ` month ` , ` dayOfMonth ` , ` hour ` , and so on up to ` nanosecond ` .
52
+ The property ` dayOfWeek ` shows what weekday that date is,
53
+ and ` dayOfYear ` shows the day number since the beginning of a year.
54
+
52
55
53
56
Additional time zones can be acquired by their string identifier with the ` TimeZone.of(id: String) ` function.
54
57
``` kotlin
55
58
val tzBerlin = TimeZone .of(" Europe/Berlin" )
56
59
val datetimeInBerlin = currentMoment.toLocalDateTime(tzBerlin)
57
60
```
58
61
62
+ ` LocalDateTime ` instance can be constructed from individual components:
63
+
64
+ ``` kotlin
65
+ val kotlinReleaseDateTime = LocalDateTime (2016 , 2 , 15 , 16 , 57 , 0 , 0 )
66
+ ```
67
+
68
+ An instant can be obtained from ` LocalDateTime ` by interpreting it as a time moment
69
+ in a particular ` TimeZone ` :
70
+
71
+ ``` kotlin
72
+ val kotlinReleaseInstant = kotlinReleaseDateTime.toInstant(TimeZone .of(" UTC+3" ))
73
+ ```
74
+
59
75
### Getting local date components
60
76
61
77
` LocalDate ` type represents local date without time. You can obtain it from ` Instant `
@@ -67,6 +83,11 @@ val today: LocalDate = now.toLocalDateTime(TimeZone.SYSTEM).date
67
83
```
68
84
Note, that today's date really depends on the time zone in which you're observing the current moment.
69
85
86
+ ` LocalDate ` can be constructed from three components, year, month, and day:
87
+ ``` kotlin
88
+ val knownDate = LocalDate (2020 , 2 , 21 )
89
+ ```
90
+
70
91
### Converting instant to and from unix time
71
92
72
93
An ` Instant ` can be converted to unix millisecond time with the ` toUnixMillis() ` function.
@@ -88,17 +109,16 @@ val instantBefore = Instant.parse("2010-06-01T22:19:44.475Z")
88
109
Alternatively, ` String.to...() ` extension functions can be used instead of ` parse ` ,
89
110
where it feels more convenient:
90
111
112
+ ` LocalDateTime ` uses the similar format, but without ` Z ` UTC time zone designator in the end.
113
+
114
+ ` LocalDate ` uses format with just year, month, and date components, e.g. ` 2010-06-01 ` .
115
+
91
116
``` kotlin
92
117
" 2010-06-01T22:19:44.475Z" .toInstant()
93
118
" 2010-06-01T22:19:44" .toLocalDateTime()
94
119
" 2010-06-01" .toLocalDate()
95
120
```
96
121
97
- ` LocalDateTime ` uses the similar format, but without ` Z ` UTC time zone designator in the end.
98
-
99
- ` LocalDate ` uses format with just year, month, and date components, e.g. ` 2010-06-01 ` .
100
-
101
-
102
122
### Instant arithmetic
103
123
104
124
``` kotlin
@@ -166,4 +186,8 @@ git submodule init
166
186
git submodule update
167
187
```
168
188
189
+ The path to JDK 8 must be specified either with the environment variable ` JDK_8 ` or
190
+ with the gradle property ` JDK_8 ` . For local builds, you can use a later version of JDK if you don't have that
191
+ version installed.
192
+
169
193
After that, the project can be opened in IDEA and built with Gradle.
0 commit comments