-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDateAndTime.kt
More file actions
26 lines (18 loc) · 791 Bytes
/
DateAndTime.kt
File metadata and controls
26 lines (18 loc) · 791 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
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
fun main() {
//current Date and Time in Default Format.
val current = LocalDateTime.now()
println("Current Date and Time is $current")
// Current Date and Time in Localised Style
val current1 = LocalDateTime.now()
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)
val formatted = current1.format(formatter)
println("Current date and time is : $formatted")
//Current Date and Time with Pattern.
val current2 = LocalDateTime.now()
val formatter1 = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss:SSS")
val formatted1 = current2.format(formatter1)
println("Current date and time is : $formatted1 ")
}