LocalDate represents just a date, not both date and time.
How can I represent both date and time?
Use LocalDateTime class to represent both the date and time.
Find the below working application.
LocalDateDemo1.java
package com.sample.app.time;
import java.time.LocalDate;
import java.time.LocalDateTime;
public class LocalDateDemo1 {
public static void main(String args[]) {
String localDateResponse = LocalDate.now().toString();
String localDateTimeResponse = LocalDateTime.now().toString();
System.out.println("localDateResponse -> " + localDateResponse);
System.out.println("localDateTimeResponse -> " + localDateTimeResponse);
}
}
Output
localDateResponse -> 2021-10-24 localDateTimeResponse -> 2021-10-24T19:31:58.170108
Previous Next Home
No comments:
Post a Comment