-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewDateTimeExample.java
More file actions
30 lines (24 loc) · 906 Bytes
/
NewDateTimeExample.java
File metadata and controls
30 lines (24 loc) · 906 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
package com.learn.dates;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
public class NewDateTimeExample {
public static void main(String[] args) {
/**
* LocalDate is a type Temporal
*/
LocalDate localDate = LocalDate.now();
System.out.println("LocalDate : " + localDate); // gives current machine local date.
/**
* LocalTime is also of type Temporal
* it also implements Comparable<LocalTime>
*/
LocalTime localTime = LocalTime.now();
System.out.println("LocalTime : " + localTime); // gives current time of machine.
/**
* LocalDateTime is a combination of both.
*/
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println("LocalDatTime : " + localDateTime); // gives machine date and time together
}
}