The toString() method of a LocalDate class is used to get this date as a String, such as 2019-01-01.The output will be in the ISO-8601 format uuuu-MM-dd.
Syntax:
public String toString()
Parameters: This method does not accepts any parameters.
Return value: This method returns String which is the representation of this date, not null.
Below programs illustrate the toString() method:
Program 1:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
LocalDate localD
= LocalDate.parse( "2018-12-06" );
System.out.println( "LocalDate: "
+ localD.toString());
}
}
|
Output:
LocalDate: 2018-12-06
Program 2:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
LocalDate localD
= LocalDate.parse( "2021-06-30" );
System.out.println( "LocalDate: "
+ localD.toString());
}
}
|
Output:
LocalDate: 2021-06-30
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#toString()
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
17 Dec, 2018
Like Article
Save Article