Skip to content

Commit f22c545

Browse files
committed
New Date/Time API's
1 parent d533767 commit f22c545

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.learn.dates;
2+
3+
import java.time.LocalDate;
4+
import java.time.LocalDateTime;
5+
import java.time.LocalTime;
6+
7+
public class NewDateTimeExample {
8+
9+
public static void main(String[] args) {
10+
11+
/**
12+
* LocalDate is a type Temporal
13+
*/
14+
LocalDate localDate = LocalDate.now();
15+
System.out.println("LocalDate : " + localDate); // gives current machine local date.
16+
17+
/**
18+
* LocalTime is also of type Temporal
19+
* it also implements Comparable<LocalTime>
20+
*/
21+
LocalTime localTime = LocalTime.now();
22+
System.out.println("LocalTime : " + localTime); // gives current time of machine.
23+
24+
/**
25+
* LocalDateTime is a combination of both.
26+
*/
27+
LocalDateTime localDateTime = LocalDateTime.now();
28+
System.out.println("LocalDatTime : " + localDateTime); // gives machine date and time together
29+
}
30+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ This repository contains the basic &amp; advance level examples related to Java
6969
* [default and static methods in Interface](Modern-Java-Examples/src/com/learn/defaults/Multiplier.java)
7070
* [default method Multiple Inheritance](Modern-Java-Examples/src/com/learn/defaults/Client123.java)
7171
* [Interfaces with same method signature Conflicts](Modern-Java-Examples/src/com/learn/defaults/Client14.java)
72+
* **New Date/Time API's**
73+
* [LocalDate, LocalTime and LocalDateTime](Modern-Java-Examples/src/com/learn/dates/NewDateTimeExample.java)
7274

7375
<hr />
7476

0 commit comments

Comments
 (0)