0 votes
326 views
in Java by
How will you get current date and time using Java 8 Date and TIme API?

1 Answer

0 votes
by (3.7k points)
Java 8 provides the following core Date and Time API Classess:-

1. LocalDate
2. LocalTime
3. LocalDateTime

The  LocalDate, LocalTime and LocalDateTime denotes the current date and time in context of Observer.

Use now() method of LocalDate to get current date:-
LocalDate currentDate = LocalDate.now();
System.out.println("Current Date: " + currentDate);

Output:- Current Date: 2019-02-06

Use now() method of LocalDate to get current date:-
LocalTime currentTime = LocalTime.now();
System.out.println("Current Time: " + currentTime);

Output:- Current Time: 23:17:51.817

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...